Debian Codegraph @

addons/l10n_my_edi/models/account_move_line.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2 from odoo.addons.l10n_my_edi.models.product_template import CLASSIFICATION_CODES_LIST
3
4 from odoo import api, fields, models
5
6
7 class AccountMoveLine(models.Model):
8 _inherit = "account.move.line"
9
10 # ------------------
11 # Fields declaration
12 # ------------------
13
14 l10n_my_edi_classification_code = fields.Selection(
15 string="Malaysian classification code",
16 selection=CLASSIFICATION_CODES_LIST,
17 compute="_compute_l10n_my_edi_classification_code",
18 store=True,
19 readonly=False,
20 copy=False,
21 )
22
23 # --------------------------------
24 # Compute, inverse, search methods
25 # --------------------------------
26
27 @api.depends("product_id.product_tmpl_id")
28 def _compute_l10n_my_edi_classification_code(self):
29 """ Default to the product classification if any """
30 for line in self:
31 # We don't want to automatically update it on invoices that were sent to MyInvois
32 if not line.move_id.l10n_my_edi_state:
33 # There is no product in case of downpayments, so we need to manually set the class code
34 if 'is_downpayment' in line and line.is_downpayment:
35 line.l10n_my_edi_classification_code = "022"
36 else:
37 line.l10n_my_edi_classification_code = line.product_id.product_tmpl_id.l10n_my_edi_classification_code or line.l10n_my_edi_classification_code