changes
This commit is contained in:
@@ -84,6 +84,15 @@ class FusionADPDeviceCode(models.Model):
|
||||
default=fields.Datetime.now,
|
||||
)
|
||||
|
||||
# ==========================================================================
|
||||
# REVERSE LINK TO PRODUCTS
|
||||
# ==========================================================================
|
||||
product_template_ids = fields.One2many(
|
||||
'product.template',
|
||||
'x_fc_adp_device_code_id',
|
||||
string='Linked Products',
|
||||
)
|
||||
|
||||
# ==========================================================================
|
||||
# SQL CONSTRAINTS
|
||||
# ==========================================================================
|
||||
@@ -92,6 +101,28 @@ class FusionADPDeviceCode(models.Model):
|
||||
'Device code must be unique!'),
|
||||
]
|
||||
|
||||
# ==========================================================================
|
||||
# WRITE OVERRIDE - push changes to linked products
|
||||
# ==========================================================================
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
sync_fields = {'adp_price', 'device_code'}
|
||||
if sync_fields & set(vals):
|
||||
products = self.env['product.template'].sudo().search([
|
||||
('x_fc_adp_device_code_id', 'in', self.ids)
|
||||
])
|
||||
if products:
|
||||
for product in products:
|
||||
update = {}
|
||||
device = product.x_fc_adp_device_code_id
|
||||
if 'adp_price' in vals:
|
||||
update['x_fc_adp_price'] = device.adp_price
|
||||
if 'device_code' in vals:
|
||||
update['x_fc_adp_device_code'] = device.device_code
|
||||
if update:
|
||||
product.sudo().write(update)
|
||||
return res
|
||||
|
||||
# ==========================================================================
|
||||
# COMPUTED FIELDS
|
||||
# ==========================================================================
|
||||
|
||||
Reference in New Issue
Block a user