From ec45440400f946e10a4f6f00b60a0b79dff5550b Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Wed, 22 Apr 2026 19:57:43 +0200 Subject: [PATCH] Report name --- modules/purchase_trade/configuration.py | 63 ++++++++++++++++ modules/purchase_trade/tests/test_module.py | 74 +++++++++++++++++++ .../view/template_configuration_form.xml | 20 +++++ modules/sale/sale.xml | 4 +- 4 files changed, 159 insertions(+), 2 deletions(-) diff --git a/modules/purchase_trade/configuration.py b/modules/purchase_trade/configuration.py index 244cc50..9a13f54 100644 --- a/modules/purchase_trade/configuration.py +++ b/modules/purchase_trade/configuration.py @@ -1,19 +1,82 @@ from trytond.model import ModelSingleton, ModelSQL, ModelView, fields +from trytond.pool import Pool class Configuration(ModelSingleton, ModelSQL, ModelView): "Purchase Trade Configuration" __name__ = 'purchase_trade.configuration' + _REPORT_LABELS = ( + ('sale_report_label', 'sale', 'report_sale', 'Proforma'), + ('sale_bill_report_label', 'sale', 'report_bill', 'Draft'), + ('invoice_report_label', 'account_invoice', 'report_invoice', + 'Invoice'), + ('invoice_cndn_report_label', 'account_invoice', + 'report_invoice_ict_final', 'CN/DN'), + ('invoice_prepayment_report_label', 'account_invoice', + 'report_prepayment', 'Prepayment'), + ('invoice_payment_order_report_label', 'purchase_trade', + 'report_payment_order', 'Payment Order'), + ('purchase_report_label', 'purchase', 'report_purchase', 'Purchase'), + ('shipment_shipping_report_label', 'stock', + 'report_shipment_in_shipping', 'Shipping instructions'), + ('shipment_insurance_report_label', 'purchase_trade', + 'report_shipment_in_insurance', 'Insurance'), + ('shipment_packing_list_report_label', 'purchase_trade', + 'report_shipment_in_packing_list', 'Packing List'), + ) + pricing_rule = fields.Text("Pricing Rule") sale_report_template = fields.Char("Sale Template") + sale_report_label = fields.Char("Sale Menu Label") sale_bill_report_template = fields.Char("Sale Bill Template") + sale_bill_report_label = fields.Char("Sale Bill Menu Label") sale_final_report_template = fields.Char("Sale Final Template") invoice_report_template = fields.Char("Invoice Template") + invoice_report_label = fields.Char("Invoice Menu Label") invoice_cndn_report_template = fields.Char("CN/DN Template") + invoice_cndn_report_label = fields.Char("CN/DN Menu Label") invoice_prepayment_report_template = fields.Char("Prepayment Template") + invoice_prepayment_report_label = fields.Char("Prepayment Menu Label") invoice_payment_order_report_template = fields.Char("Payment Order Template") + invoice_payment_order_report_label = fields.Char( + "Payment Order Menu Label") purchase_report_template = fields.Char("Purchase Template") + purchase_report_label = fields.Char("Purchase Menu Label") shipment_shipping_report_template = fields.Char("Shipping Template") + shipment_shipping_report_label = fields.Char("Shipping Menu Label") shipment_insurance_report_template = fields.Char("Insurance Template") + shipment_insurance_report_label = fields.Char("Insurance Menu Label") shipment_packing_list_report_template = fields.Char("Packing List Template") + shipment_packing_list_report_label = fields.Char( + "Packing List Menu Label") + + @classmethod + def create(cls, vlist): + records = super().create(vlist) + cls._sync_report_labels(records) + return records + + @classmethod + def write(cls, *args): + super().write(*args) + cls._sync_report_labels(sum(args[::2], [])) + + @classmethod + def _sync_report_labels(cls, records): + if not records: + return + pool = Pool() + ModelData = pool.get('ir.model.data') + ActionReport = pool.get('ir.action.report') + to_write = [] + for record in records: + for field_name, module, xml_id, default_label in cls._REPORT_LABELS: + label = (getattr(record, field_name, '') or '').strip() + action_id = ModelData.get_id(module, xml_id) + action = ActionReport(action_id) + target_label = label or default_label + if getattr(action, 'name', '') != target_label: + to_write.extend(([action], {'name': target_label})) + if to_write: + ActionReport.write(*to_write) diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py index 8601a30..958337c 100644 --- a/modules/purchase_trade/tests/test_module.py +++ b/modules/purchase_trade/tests/test_module.py @@ -1098,6 +1098,80 @@ class PurchaseTradeTestCase(ModuleTestCase): }), 'stock/packing_list_custom.fodt') + def test_configuration_syncs_report_menu_labels(self): + 'document template configuration updates report menu labels' + Configuration = Pool().get('purchase_trade.configuration') + config = Mock( + sale_report_label='Offer', + sale_bill_report_label='', + invoice_report_label='', + invoice_cndn_report_label='', + invoice_prepayment_report_label='', + invoice_payment_order_report_label='Wire Order', + purchase_report_label='', + shipment_shipping_report_label='', + shipment_insurance_report_label='', + shipment_packing_list_report_label='', + ) + action_sale = Mock(spec=['name']) + action_sale.name = 'Proforma' + action_bill = Mock(spec=['name']) + action_bill.name = 'Old Draft' + action_invoice = Mock(spec=['name']) + action_invoice.name = 'Invoice' + action_cndn = Mock(spec=['name']) + action_cndn.name = 'CN/DN' + action_prepayment = Mock(spec=['name']) + action_prepayment.name = 'Prepayment' + action_payment_order = Mock(spec=['name']) + action_payment_order.name = 'Payment Order' + action_purchase = Mock(spec=['name']) + action_purchase.name = 'Purchase' + action_shipping = Mock(spec=['name']) + action_shipping.name = 'Shipping instructions' + action_insurance = Mock(spec=['name']) + action_insurance.name = 'Insurance' + action_packing = Mock(spec=['name']) + action_packing.name = 'Packing List' + actions = { + 1: action_sale, + 2: action_bill, + 3: action_invoice, + 4: action_cndn, + 5: action_prepayment, + 6: action_payment_order, + 7: action_purchase, + 8: action_shipping, + 9: action_insurance, + 10: action_packing, + } + + model_data = Mock() + model_data.get_id.side_effect = list(actions.keys()) + action_report = Mock() + action_report.side_effect = actions.__getitem__ + + def get_model(name): + return { + 'ir.model.data': model_data, + 'ir.action.report': action_report, + }[name] + + with patch( + 'trytond.modules.purchase_trade.configuration.Pool' + ) as PoolMock: + PoolMock.return_value.get.side_effect = get_model + + Configuration._sync_report_labels([config]) + + self.assertEqual( + action_report.write.call_args.args, + ( + [actions[1]], {'name': 'Offer'}, + [actions[2]], {'name': 'Draft'}, + [actions[6]], {'name': 'Wire Order'}, + )) + def test_shipment_insurance_helpers_use_fee_and_controller(self): 'shipment insurance helpers read insurance fee and shipment context' ShipmentIn = Pool().get('stock.shipment.in') diff --git a/modules/purchase_trade/view/template_configuration_form.xml b/modules/purchase_trade/view/template_configuration_form.xml index c94eba3..d72b4f5 100644 --- a/modules/purchase_trade/view/template_configuration_form.xml +++ b/modules/purchase_trade/view/template_configuration_form.xml @@ -3,32 +3,52 @@