Skip to content

Commit

Permalink
[REF] Sale order typology moved to sale_cart
Browse files Browse the repository at this point in the history
  • Loading branch information
qgroulard committed Oct 5, 2023
1 parent 2c08306 commit 87be8b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
15 changes: 12 additions & 3 deletions sale_cart/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions shopinvader_restapi/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"base_vat",
"component_event",
"sale",
"sale_cart",
"sale_discount_display_amount",
"server_environment",
"onchange_helper",
Expand Down
33 changes: 11 additions & 22 deletions shopinvader_restapi/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 87be8b0

Please sign in to comment.