Debian Codegraph @

addons/l10n_hr_edi/models/account_move_line.py

raw
1 from odoo import api, models, fields
2 from odoo.tools.sql import column_exists, create_column
3
4
5 class AccountMoveLine(models.Model):
6 _inherit = 'account.move.line'
7
8 l10n_hr_kpd_category_id = fields.Many2one(
9 comodel_name='l10n_hr.kpd.category',
10 string="KPD category",
11 compute='_compute_l10n_hr_product_id_kpd',
12 store=True,
13 readonly=False,
14 )
15
16 @api.depends('product_id')
17 def _compute_l10n_hr_product_id_kpd(self):
18 """Copy KPD code from product template when a product is selected for the line."""
19 for line in self:
20 if line.product_id:
21 line.l10n_hr_kpd_category_id = line.product_id.l10n_hr_kpd_category_id
22
23 def _auto_init(self):
24 if not column_exists(self.env.cr, 'account_move_line', 'l10n_hr_kpd_category_id'):
25 create_column(self.env.cr, 'account_move_line', 'l10n_hr_kpd_category_id', 'integer')
26 return super()._auto_init()