From 87be8b0ebc3a5f6734150f92e940808eaa19fa04 Mon Sep 17 00:00:00 2001 From: Quentin Groulard Date: Thu, 5 Oct 2023 18:47:51 +0200 Subject: [PATCH] [REF] Sale order typology moved to sale_cart --- sale_cart/models/sale_order.py | 15 ++++++++++--- shopinvader_restapi/__manifest__.py | 1 + shopinvader_restapi/models/sale.py | 33 ++++++++++------------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/sale_cart/models/sale_order.py b/sale_cart/models/sale_order.py index 97364eb755..982bbc8f16 100644 --- a/sale_cart/models/sale_order.py +++ b/sale_cart/models/sale_order.py @@ -10,17 +10,26 @@ class SaleOrder(models.Model): typology = fields.Selection([("sale", "Sale"), ("cart", "Cart")], default="sale") + def _confirm_cart(self): + self.ensure_one() + self.write({"typology": "sale"}) + def action_confirm_cart(self): for record in self: if record.typology == "sale": # cart is already confirmed continue - record.write({"typology": "sale"}) + record._confirm_cart() return True + def _confirm_sale(self): + self.ensure_one() + if self.typology != "sale": + self.typology = "sale" + def action_confirm(self): res = super(SaleOrder, self).action_confirm() for record in self: - if record.state != "draft" and record.typology != "sale": - record.typology = "sale" + if record.state != "draft": + record._confirm_sale() return res diff --git a/shopinvader_restapi/__manifest__.py b/shopinvader_restapi/__manifest__.py index a224472ee4..6f001570c8 100644 --- a/shopinvader_restapi/__manifest__.py +++ b/shopinvader_restapi/__manifest__.py @@ -20,6 +20,7 @@ "base_vat", "component_event", "sale", + "sale_cart", "sale_discount_display_amount", "server_environment", "onchange_helper", diff --git a/shopinvader_restapi/models/sale.py b/shopinvader_restapi/models/sale.py index 759c0ed8a6..ea3371701b 100644 --- a/shopinvader_restapi/models/sale.py +++ b/shopinvader_restapi/models/sale.py @@ -14,7 +14,6 @@ class SaleOrder(models.Model): _name = "sale.order" _inherit = ["sale.order", "track.external.mixin"] - typology = fields.Selection([("sale", "Sale"), ("cart", "Cart")], default="sale") shopinvader_backend_id = fields.Many2one("shopinvader.backend", "Backend") current_step_id = fields.Many2one( "shopinvader.cart.step", "Current Cart Step", readonly=True @@ -62,28 +61,18 @@ def _prepare_invoice(self): res["shopinvader_backend_id"] = self.shopinvader_backend_id.id return res - def action_confirm_cart(self): - for record in self: - if record.typology == "sale": - # cart is already confirmed - continue - record.write({"typology": "sale"}) - if record.shopinvader_backend_id: - record.shopinvader_backend_id._send_notification( - "cart_confirmation", record - ) - return True + def _confirm_cart(self): + self.ensure_one() + res = super()._confirm_cart() + if self.shopinvader_backend_id: + self.shopinvader_backend_id._send_notification("cart_confirmation", self) + return res - def action_confirm(self): - res = super(SaleOrder, self).action_confirm() - for record in self: - if record.state != "draft" and record.shopinvader_backend_id: - # If we confirm a cart directly we change the typology - if record.typology != "sale": - record.typology = "sale" - record.shopinvader_backend_id._send_notification( - "sale_confirmation", record - ) + def _confirm_sale(self): + self.ensure_one() + res = super()._confirm_sale() + if self.shopinvader_backend_id: + self.shopinvader_backend_id._send_notification("sale_confirmation", self) return res def reset_price_tax(self):