93 lines
4.4 KiB
Python
93 lines
4.4 KiB
Python
from trytond.model import ModelSingleton, ModelSQL, ModelView, fields
|
|
from trytond.pool import Pool
|
|
from trytond.transaction import Transaction
|
|
|
|
|
|
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_packing_list_report_label', 'purchase_trade',
|
|
'report_invoice_packing_list', 'Packing List'),
|
|
('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_coo_report_label', 'purchase_trade',
|
|
'report_shipment_in_coo', 'COO'),
|
|
('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_packing_list_report_template = fields.Char("Packing List Template")
|
|
invoice_packing_list_report_label = fields.Char("Packing List 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_coo_report_template = fields.Char("COO Template")
|
|
shipment_coo_report_label = fields.Char("COO 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:
|
|
with Transaction().set_user(0):
|
|
ActionReport.write(*to_write)
|