diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py index f448ea965..36e440598 100644 --- a/yuthon_property_approval/models/inherit_yuthon_property.py +++ b/yuthon_property_approval/models/inherit_yuthon_property.py @@ -1,3 +1,4 @@ +import logging from datetime import datetime, timedelta, date from odoo.tools.float_utils import float_round from numpy.ma.core import default_filler @@ -664,6 +665,7 @@ class PropertyAccountsReceivable(models.Model): is_refunded = fields.Boolean(string='是否已退款', compute='_compute_is_refunded', store=True) penalty = fields.Float(string="违约金基数") penalty_date = fields.Date(string="违约金日期") + penalty_ratio_value = fields.Float(string="违约金比例", digits=(16, 6)) # 从合同 percentage_liquidated_damages.name 带入,千分比需6位精度 invoice_type = fields.Selection( [('ordinary_invoice', '普通发票'), ('vat_invoice', '增值税发票')], string='发票类型', default='ordinary_invoice') # 报表新增字段 @@ -1165,6 +1167,23 @@ class PropertyAccountsReceivable(models.Model): 'is_reconciliation': True }) + def fill_penalty_ratio_value(self): + # 服务器动作调用,通过 active_ids 获取选中的记录集 + records = self.env["property.accounts.receivable"].browse( + self._context.get('active_ids', self._context.get('active_id'))) + # 如果 context 没有 active_ids(比如通过其他方式调用),回退到 self + if not records: + records = self + # 从关联合同 percentage_liquidated_damages.name 读取违约金比例并写入 penalty_ratio_value + updated = 0 + for record in records: + if record.contract_id and record.contract_id.percentage_liquidated_damages: + record.penalty_ratio_value = float(record.contract_id.percentage_liquidated_damages.name) + updated += 1 + # 调试日志:打印处理了多少条记录 + _logger = logging.getLogger(__name__) + _logger.info('fill_penalty_ratio_value: 处理 %d 条记录,成功写入 %d 条', len(records), updated) + def all_penalty_date(self): receivable_ids= self.env["property.accounts.receivable"].browse(self._context.get('active_ids', self._context.get('active_id'))) for receivable in receivable_ids: diff --git a/yuthon_property_approval/views/inherit_yuthon_property_views.xml b/yuthon_property_approval/views/inherit_yuthon_property_views.xml index 2a81f2f2d..cd5c6454c 100644 --- a/yuthon_property_approval/views/inherit_yuthon_property_views.xml +++ b/yuthon_property_approval/views/inherit_yuthon_property_views.xml @@ -393,6 +393,7 @@ +