changes
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
# Part of the Fusion Claim Assistant product family.
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
@@ -11,12 +12,26 @@ class ProductTemplate(models.Model):
|
||||
|
||||
# ==========================================================================
|
||||
# ADP PRODUCT FIELDS
|
||||
# These are the module's own fields - independent of Odoo Studio
|
||||
# ==========================================================================
|
||||
|
||||
x_fc_adp_device_code = fields.Char(
|
||||
x_fc_is_adp_product = fields.Boolean(
|
||||
string='ADP Product',
|
||||
default=False,
|
||||
tracking=True,
|
||||
help='Toggle to mark this as an ADP product. Shows ADP fields when enabled.',
|
||||
)
|
||||
|
||||
x_fc_adp_device_code_id = fields.Many2one(
|
||||
'fusion.adp.device.code',
|
||||
string='ADP Device Code',
|
||||
help='Device code used for ADP claims export',
|
||||
ondelete='set null',
|
||||
tracking=True,
|
||||
help='Link to the ADP Mobility Manual device code record',
|
||||
)
|
||||
|
||||
x_fc_adp_device_code = fields.Char(
|
||||
string='Device Code',
|
||||
help='Device code string used for ADP claims export',
|
||||
copy=True,
|
||||
tracking=True,
|
||||
)
|
||||
@@ -24,16 +39,30 @@ class ProductTemplate(models.Model):
|
||||
x_fc_adp_price = fields.Float(
|
||||
string='ADP Price',
|
||||
digits='Product Price',
|
||||
help='ADP retail price for this product. Used in ADP reports and claims.',
|
||||
help='ADP retail price from the device codes database.',
|
||||
copy=True,
|
||||
tracking=True,
|
||||
)
|
||||
|
||||
x_fc_is_adp_product = fields.Boolean(
|
||||
string='Is ADP Product',
|
||||
compute='_compute_is_adp_product',
|
||||
x_fc_adp_device_type = fields.Char(
|
||||
related='x_fc_adp_device_code_id.device_type',
|
||||
string='Device Type',
|
||||
store=True,
|
||||
help='Indicates if this product has ADP pricing set up',
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
x_fc_adp_build_type = fields.Selection(
|
||||
related='x_fc_adp_device_code_id.build_type',
|
||||
string='Build Type',
|
||||
store=True,
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
x_fc_adp_max_quantity = fields.Integer(
|
||||
related='x_fc_adp_device_code_id.max_quantity',
|
||||
string='Max Quantity',
|
||||
store=True,
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
# ==========================================================================
|
||||
@@ -117,49 +146,65 @@ class ProductTemplate(models.Model):
|
||||
x_fc_package_info = fields.Text(string='Package Information')
|
||||
|
||||
# ==========================================================================
|
||||
# COMPUTED FIELDS
|
||||
# ONCHANGE / CONSTRAINTS
|
||||
# ==========================================================================
|
||||
|
||||
@api.depends('x_fc_adp_device_code', 'x_fc_adp_price')
|
||||
def _compute_is_adp_product(self):
|
||||
"""Determine if this is an ADP product based on having device code or price."""
|
||||
@api.onchange('x_fc_adp_device_code_id')
|
||||
def _onchange_adp_device_code_id(self):
|
||||
"""Populate device code string and price from the selected device record."""
|
||||
if self.x_fc_adp_device_code_id:
|
||||
self.x_fc_adp_device_code = self.x_fc_adp_device_code_id.device_code
|
||||
self.x_fc_adp_price = self.x_fc_adp_device_code_id.adp_price
|
||||
else:
|
||||
self.x_fc_adp_device_code = False
|
||||
self.x_fc_adp_price = 0.0
|
||||
|
||||
@api.constrains('x_fc_is_adp_product', 'x_fc_adp_device_code_id')
|
||||
def _check_adp_product_device_code(self):
|
||||
for product in self:
|
||||
product.x_fc_is_adp_product = bool(
|
||||
product.x_fc_adp_device_code or product.x_fc_adp_price
|
||||
)
|
||||
if product.x_fc_is_adp_product and not product.x_fc_adp_device_code_id:
|
||||
raise ValidationError(
|
||||
_("'%s' is marked as an ADP Product but has no ADP Device Code selected.") % product.name
|
||||
)
|
||||
|
||||
# ==========================================================================
|
||||
# HELPER METHODS
|
||||
# ==========================================================================
|
||||
|
||||
def get_adp_price(self):
|
||||
"""
|
||||
Get ADP price with fallback to Studio field.
|
||||
|
||||
"""Get ADP price, preferring the linked device code record.
|
||||
|
||||
Checks in order:
|
||||
1. x_fc_adp_price (module field)
|
||||
2. list_price (default product price)
|
||||
1. Linked device code record price
|
||||
2. x_fc_adp_price (stored field)
|
||||
3. list_price (default product price)
|
||||
"""
|
||||
self.ensure_one()
|
||||
|
||||
|
||||
if self.x_fc_adp_device_code_id and self.x_fc_adp_device_code_id.adp_price:
|
||||
return self.x_fc_adp_device_code_id.adp_price
|
||||
|
||||
if self.x_fc_adp_price:
|
||||
return self.x_fc_adp_price
|
||||
|
||||
|
||||
return self.list_price or 0.0
|
||||
|
||||
def get_adp_device_code(self):
|
||||
"""
|
||||
Get ADP device code.
|
||||
|
||||
"""Get ADP device code, preferring the linked device code record.
|
||||
|
||||
Checks in order:
|
||||
1. x_fc_adp_device_code (module field)
|
||||
2. default_code (internal reference)
|
||||
1. Linked device code record
|
||||
2. x_fc_adp_device_code (stored char)
|
||||
3. default_code (internal reference)
|
||||
"""
|
||||
self.ensure_one()
|
||||
|
||||
|
||||
if self.x_fc_adp_device_code_id:
|
||||
return self.x_fc_adp_device_code_id.device_code or ''
|
||||
|
||||
if self.x_fc_adp_device_code:
|
||||
return self.x_fc_adp_device_code
|
||||
|
||||
|
||||
return self.default_code or ''
|
||||
|
||||
# ==========================================================================
|
||||
|
||||
Reference in New Issue
Block a user