feat: implement automated decimal precision sync for reward points across loyalty models and PoS configuration
This commit is contained in:
parent
cfa7ceaf1a
commit
05462f0ffa
@ -19,7 +19,6 @@ A new 'Reward Point' decimal precision record is created, and the POS Settings v
|
|||||||
'depends': ['point_of_sale', 'pos_loyalty', 'loyalty'],
|
'depends': ['point_of_sale', 'pos_loyalty', 'loyalty'],
|
||||||
'data': [
|
'data': [
|
||||||
'data/decimal_precision_data.xml',
|
'data/decimal_precision_data.xml',
|
||||||
'views/res_config_settings_views.xml',
|
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'auto_install': False,
|
'auto_install': False,
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
from . import loyalty_rule
|
from . import loyalty_models
|
||||||
from . import pos_config
|
from . import pos_config
|
||||||
from . import res_config_settings
|
from . import decimal_precision
|
||||||
|
|||||||
15
models/decimal_precision.py
Normal file
15
models/decimal_precision.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
class DecimalPrecision(models.Model):
|
||||||
|
_inherit = 'decimal.precision'
|
||||||
|
|
||||||
|
def write(self, vals):
|
||||||
|
res = super(DecimalPrecision, self).write(vals)
|
||||||
|
if 'digits' in vals:
|
||||||
|
for record in self:
|
||||||
|
if record.name == 'Reward Point':
|
||||||
|
# Sync to all pos.config records
|
||||||
|
# We iterate to avoid 'Expected singleton' error in multi-company
|
||||||
|
for config in self.env['pos.config'].sudo().search([]):
|
||||||
|
config.write({'reward_point_digits': record.digits})
|
||||||
|
return res
|
||||||
27
models/loyalty_models.py
Normal file
27
models/loyalty_models.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
class LoyaltyRule(models.Model):
|
||||||
|
_inherit = 'loyalty.rule'
|
||||||
|
|
||||||
|
reward_point_amount = fields.Float(digits='Reward Point')
|
||||||
|
|
||||||
|
class LoyaltyReward(models.Model):
|
||||||
|
_inherit = 'loyalty.reward'
|
||||||
|
|
||||||
|
required_points = fields.Float(digits='Reward Point')
|
||||||
|
|
||||||
|
class LoyaltyCard(models.Model):
|
||||||
|
_inherit = 'loyalty.card'
|
||||||
|
|
||||||
|
points = fields.Float(digits='Reward Point')
|
||||||
|
|
||||||
|
class LoyaltyHistory(models.Model):
|
||||||
|
_inherit = 'loyalty.history'
|
||||||
|
|
||||||
|
issued = fields.Float(digits='Reward Point')
|
||||||
|
used = fields.Float(digits='Reward Point')
|
||||||
|
|
||||||
|
class PosOrderLine(models.Model):
|
||||||
|
_inherit = 'pos.order.line'
|
||||||
|
|
||||||
|
points_cost = fields.Float(digits='Reward Point')
|
||||||
@ -1,6 +0,0 @@
|
|||||||
from odoo import fields, models
|
|
||||||
|
|
||||||
class LoyaltyRule(models.Model):
|
|
||||||
_inherit = 'loyalty.rule'
|
|
||||||
|
|
||||||
reward_point_amount = fields.Float(digits='Reward Point')
|
|
||||||
@ -1,6 +1,12 @@
|
|||||||
from odoo import fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
class PosConfig(models.Model):
|
class PosConfig(models.Model):
|
||||||
_inherit = 'pos.config'
|
_inherit = 'pos.config'
|
||||||
|
|
||||||
reward_point_digits = fields.Integer(string="Reward Point Digits", default=2)
|
reward_point_digits = fields.Integer(string="Reward Point Digits", default=2)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _load_pos_data_fields(self, config):
|
||||||
|
fields_list = super()._load_pos_data_fields(config)
|
||||||
|
fields_list.append('reward_point_digits')
|
||||||
|
return fields_list
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
from odoo import api, fields, models
|
|
||||||
|
|
||||||
class ResConfigSettings(models.TransientModel):
|
|
||||||
_inherit = 'res.config.settings'
|
|
||||||
|
|
||||||
pos_reward_point_digits = fields.Integer(
|
|
||||||
string="Reward Point Digits",
|
|
||||||
config_parameter='pos_reward_point_digits',
|
|
||||||
default=2
|
|
||||||
)
|
|
||||||
|
|
||||||
@api.model
|
|
||||||
def get_values(self):
|
|
||||||
res = super(ResConfigSettings, self).get_values()
|
|
||||||
precision = self.env.ref('pos_reward_point_digits.dp_reward_point', raise_if_not_found=False)
|
|
||||||
if precision:
|
|
||||||
res.update({
|
|
||||||
'pos_reward_point_digits': precision.digits,
|
|
||||||
})
|
|
||||||
return res
|
|
||||||
|
|
||||||
def set_values(self):
|
|
||||||
super(ResConfigSettings, self).set_values()
|
|
||||||
precision = self.env.ref('pos_reward_point_digits.dp_reward_point', raise_if_not_found=False)
|
|
||||||
if precision and precision.digits != self.pos_reward_point_digits:
|
|
||||||
precision.sudo().digits = self.pos_reward_point_digits
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<odoo>
|
|
||||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
|
||||||
<field name="name">res.config.settings.view.form.inherit.pos_reward_point_digits</field>
|
|
||||||
<field name="model">res.config.settings</field>
|
|
||||||
<field name="inherit_id" ref="point_of_sale.res_config_settings_view_form"/>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<xpath expr="//block[@id='pos_pricing_section']" position="inside">
|
|
||||||
<setting id="reward_point_digits" string="Reward Point Digits" help="Set the number of decimal precision digits for reward points.">
|
|
||||||
<field name="pos_reward_point_digits" widget="integer"/>
|
|
||||||
</setting>
|
|
||||||
</xpath>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
</odoo>
|
|
||||||
Loading…
Reference in New Issue
Block a user