From 9429f7d2e3513e2d26b0f450a08d6ab482622334 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Sun, 26 Jul 2026 22:35:08 +0200 Subject: [PATCH] Faircot action --- modules/purchase_trade/__init__.py | 12 +-- modules/purchase_trade/stock.py | 82 +++++++++++++++---- modules/purchase_trade/stock.xml | 9 ++ .../shipment_controller_email_start_form.xml | 5 ++ .../purchase_trade/view/shipment_in_form.xml | 2 +- 5 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 modules/purchase_trade/view/shipment_controller_email_start_form.xml diff --git a/modules/purchase_trade/__init__.py b/modules/purchase_trade/__init__.py index 6377c3a..af478fa 100755 --- a/modules/purchase_trade/__init__.py +++ b/modules/purchase_trade/__init__.py @@ -195,8 +195,9 @@ def register(): stock.Move, stock.Location, stock.InvoiceLine, - stock.ShipmentIn, - stock.ShipmentWR, + stock.ShipmentIn, + stock.ShipmentControllerEmailStart, + stock.ShipmentWR, stock.ShipmentInternal, stock.ShipmentOut, stock.StatementOfFacts, @@ -336,9 +337,10 @@ def register(): lot.LotUnship, lot.LotRemove, lot.LotInvoice, - lot.LotAdding, - lot.LotImporting, - stock.FindVessel, + lot.LotAdding, + lot.LotImporting, + stock.ShipmentControllerEmail, + stock.FindVessel, stock.SofUpdate, stock.Revaluate, purchase.GoToBi, diff --git a/modules/purchase_trade/stock.py b/modules/purchase_trade/stock.py index 952c558..c3c1a64 100755 --- a/modules/purchase_trade/stock.py +++ b/modules/purchase_trade/stock.py @@ -2852,11 +2852,9 @@ class ShipmentIn(metaclass=PoolMeta): response.raise_for_status() return response.json() - @classmethod - @ModelView.button - def send(cls, shipments): - Date = Pool().get('ir.date') - Attachment = Pool().get('ir.attachment') + @classmethod + def _send_controller_email(cls, shipments, body_by_shipment=None): + Attachment = Pool().get('ir.attachment') for sh in shipments: sh.result = "Email not sent" @@ -2879,13 +2877,14 @@ class ShipmentIn(metaclass=PoolMeta): Contact = Pool().get('party.contact_mechanism') contact = Contact.search(['party','=',sh.controller.id]) if contact: - payload = { - "to": [contact[0].value], - "subject": "Request for control", - "body": sh.html_to_text(sh.instructions), - "attachments": attachment, - "meta": { - "shipment": sh.bl_number, + payload = { + "to": [contact[0].value], + "subject": "Request for control", + "body": (body_by_shipment or {}).get( + sh.id, sh.html_to_text(sh.instructions or '')), + "attachments": attachment, + "meta": { + "shipment": sh.bl_number, "controller": sh.controller.id } } @@ -2922,11 +2921,16 @@ class ShipmentIn(metaclass=PoolMeta): logger.info("PAYLOAD:%s",so_payload) data = sh.create_service_order(so_payload) logger.info("SO_NUMBER:%s",data.get('service_order_number')) - sh.result += f" / SO Nb {data.get('service_order_number')}" - sh.service_order_key = int(data.get('service_order_key')) - sh.save() - - @classmethod + sh.result += f" / SO Nb {data.get('service_order_number')}" + sh.service_order_key = int(data.get('service_order_key')) + sh.save() + + @classmethod + @ModelView.button_action('purchase_trade.act_send_controller_email') + def send(cls, shipments): + pass + + @classmethod @ModelView.button def compute(cls, shipments): Sof = Pool().get('sof.statement') @@ -3313,6 +3317,50 @@ class ShipmentIn(metaclass=PoolMeta): ] ) +class ShipmentControllerEmailStart(ModelView): + "Send Controller Email" + __name__ = 'stock.shipment.in.send.controller.email.start' + + body = fields.Text("Message", required=True) + + +class ShipmentControllerEmail(Wizard): + "Send Controller Email" + __name__ = 'stock.shipment.in.send.controller.email' + + start = StateView( + 'stock.shipment.in.send.controller.email.start', + 'purchase_trade.shipment_controller_email_start_view_form', + [ + Button("Cancel", 'end', 'tryton-cancel'), + Button("Send", 'send_', 'tryton-ok', default=True), + ]) + send_ = StateTransition() + + def _shipment(self): + Shipment = Pool().get('stock.shipment.in') + active_ids = Transaction().context.get('active_ids') or [] + if len(active_ids) != 1: + raise UserError("Select one shipment.") + return Shipment(active_ids[0]) + + def default_start(self, fields): + shipment = self._shipment() + return { + 'body': shipment.html_to_text(shipment.instructions or ''), + } + + def transition_send_(self): + Shipment = Pool().get('stock.shipment.in') + shipment = self._shipment() + Shipment._send_controller_email( + [shipment], {shipment.id: self.start.body or ''}) + return 'end' + + def end(self): + return 'reload' + + class FindVessel(Wizard): __name__ = 'stock.shipment.in.vf' start_state = 'vf' diff --git a/modules/purchase_trade/stock.xml b/modules/purchase_trade/stock.xml index 30899d3..57fc67a 100755 --- a/modules/purchase_trade/stock.xml +++ b/modules/purchase_trade/stock.xml @@ -13,6 +13,15 @@ this repository contains the full copyright notices and license terms. --> shipment_in_tree + + stock.shipment.in.send.controller.email.start + form + shipment_controller_email_start_form + + + Send email to controller + stock.shipment.in.send.controller.email + diff --git a/modules/purchase_trade/view/shipment_controller_email_start_form.xml b/modules/purchase_trade/view/shipment_controller_email_start_form.xml new file mode 100644 index 0000000..94553a1 --- /dev/null +++ b/modules/purchase_trade/view/shipment_controller_email_start_form.xml @@ -0,0 +1,5 @@ + +
+