Report name

This commit is contained in:
2026-04-22 19:57:43 +02:00
parent edb23b008c
commit ec45440400
4 changed files with 159 additions and 2 deletions

View File

@@ -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)

View File

@@ -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')

View File

@@ -3,32 +3,52 @@
<separator id="sale_templates" string="Sale" colspan="4"/>
<label name="sale_report_template"/>
<field name="sale_report_template" colspan="3"/>
<label name="sale_report_label"/>
<field name="sale_report_label" colspan="3"/>
<label name="sale_bill_report_template"/>
<field name="sale_bill_report_template" colspan="3"/>
<label name="sale_bill_report_label"/>
<field name="sale_bill_report_label" colspan="3"/>
<label name="sale_final_report_template"/>
<field name="sale_final_report_template" colspan="3"/>
<separator id="invoice_templates" string="Invoice" colspan="4"/>
<label name="invoice_report_template"/>
<field name="invoice_report_template" colspan="3"/>
<label name="invoice_report_label"/>
<field name="invoice_report_label" colspan="3"/>
<label name="invoice_cndn_report_template"/>
<field name="invoice_cndn_report_template" colspan="3"/>
<label name="invoice_cndn_report_label"/>
<field name="invoice_cndn_report_label" colspan="3"/>
<label name="invoice_prepayment_report_template"/>
<field name="invoice_prepayment_report_template" colspan="3"/>
<label name="invoice_prepayment_report_label"/>
<field name="invoice_prepayment_report_label" colspan="3"/>
<separator id="payment_templates" string="Payment" colspan="4"/>
<label name="invoice_payment_order_report_template"/>
<field name="invoice_payment_order_report_template" colspan="3"/>
<label name="invoice_payment_order_report_label"/>
<field name="invoice_payment_order_report_label" colspan="3"/>
<separator id="purchase_templates" string="Purchase" colspan="4"/>
<label name="purchase_report_template"/>
<field name="purchase_report_template" colspan="3"/>
<label name="purchase_report_label"/>
<field name="purchase_report_label" colspan="3"/>
<separator id="shipment_templates" string="Shipment" colspan="4"/>
<label name="shipment_shipping_report_template"/>
<field name="shipment_shipping_report_template" colspan="3"/>
<label name="shipment_shipping_report_label"/>
<field name="shipment_shipping_report_label" colspan="3"/>
<label name="shipment_insurance_report_template"/>
<field name="shipment_insurance_report_template" colspan="3"/>
<label name="shipment_insurance_report_label"/>
<field name="shipment_insurance_report_label" colspan="3"/>
<label name="shipment_packing_list_report_template"/>
<field name="shipment_packing_list_report_template" colspan="3"/>
<label name="shipment_packing_list_report_label"/>
<field name="shipment_packing_list_report_label" colspan="3"/>
</form>

View File

@@ -399,7 +399,7 @@ this repository contains the full copyright notices and license terms. -->
</record>
<record model="ir.action.report" id="report_sale">
<field name="name">Sale</field>
<field name="name">Proforma</field>
<field name="model">sale.sale</field>
<field name="report_name">sale.sale</field>
<field name="report">sale/sale.fodt</field>
@@ -411,7 +411,7 @@ this repository contains the full copyright notices and license terms. -->
</record>
<record model="ir.action.report" id="report_bill">
<field name="name">Bill</field>
<field name="name">Draft</field>
<field name="model">sale.sale</field>
<field name="report_name">sale.sale</field>
<field name="report">sale/bill.fodt</field>