Skip to content

Commit

Permalink
[16.0][MIG] connector_ecommerce: adapt necessary changes for correct …
Browse files Browse the repository at this point in the history
…operation in v16
  • Loading branch information
asierneiradev committed Mar 28, 2023
1 parent 6296375 commit 791a828
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 49 deletions.
12 changes: 6 additions & 6 deletions connector_ecommerce/components/line_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SpecialOrderLineBuilder(Component):
_usage = "order.line.builder"

def __init__(self, work_context):
super(SpecialOrderLineBuilder, self).__init__(work_context)
super().__init__(work_context)
self.product = None # id or browse_record
# when no product_id, fallback to a product_ref
self.product_ref = None # tuple (module, xmlid)
Expand Down Expand Up @@ -66,12 +66,12 @@ class ShippingLineBuilder(Component):
_usage = "order.line.builder.shipping"

def __init__(self, work_context):
super(ShippingLineBuilder, self).__init__(work_context)
super().__init__(work_context)
self.product_ref = ("connector_ecommerce", "product_product_shipping")
self.sequence = 999

def get_line(self):
values = super(ShippingLineBuilder, self).get_line()
values = super().get_line()
values["is_delivery"] = True
return values

Expand All @@ -84,7 +84,7 @@ class CashOnDeliveryLineBuilder(Component):
_usage = "order.line.builder.cod"

def __init__(self, work_context):
super(CashOnDeliveryLineBuilder, self).__init__(work_context)
super().__init__(work_context)
self.product_ref = ("connector_ecommerce", "product_product_cash_on_delivery")
self.sequence = 995

Expand All @@ -97,14 +97,14 @@ class GiftOrderLineBuilder(Component):
_usage = "order.line.builder.gift"

def __init__(self, work_context):
super(GiftOrderLineBuilder, self).__init__(work_context)
super().__init__(work_context)
self.product_ref = ("connector_ecommerce", "product_product_gift")
self.sign = -1
self.gift_code = None
self.sequence = 990

def get_line(self):
line = super(GiftOrderLineBuilder, self).get_line()
line = super().get_line()
if self.gift_code:
line["name"] = "{} [{}]".format(line["name"], self.gift_code)
return line
10 changes: 2 additions & 8 deletions connector_ecommerce/components/sale_order_onchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ class SaleOrderOnChange(Component):
_inherit = "ecommerce.onchange.manager"
_usage = "ecommerce.onchange.manager.sale.order"

order_onchange_fields = [
"partner_id",
"partner_shipping_id",
"payment_mode_id",
"workflow_process_id",
]
order_onchange_fields = ["partner_id"]

line_onchange_fields = ["product_id"]

Expand All @@ -85,8 +80,7 @@ def play(self, order, order_lines):
processed_order_lines = []
line_lists = [order_lines]
if "order_line" in order and order["order_line"] is not order_lines:
# we have both backend-dependent and oerp-native order
# lines.
# we have both backend-dependent and oerp-native order lines.
# oerp-native lines can have been added to map
# shipping fees with an Odoo Product
line_lists.append(order["order_line"])
Expand Down
7 changes: 0 additions & 7 deletions connector_ecommerce/migrations/14.0.1.0.1/post-migration.py

This file was deleted.

8 changes: 5 additions & 3 deletions connector_ecommerce/models/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ def action_post(self):
self.notify_invoice_validate()
return res

def action_invoice_paid(self):
res = super().action_invoice_paid()
def _invoice_paid_hook(self):
res = super()._invoice_paid_hook()
for record in self:
self._event("on_invoice_paid").notify(record)
return res

def notify_invoice_validate(self):
for record in self.filtered(lambda m: m.move_type == "out_invoice"):
for record in self:
if record.move_type != "out_invoice":
continue
self._event("on_invoice_validated").notify(record)
20 changes: 12 additions & 8 deletions connector_ecommerce/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ProductTemplate(models.Model):
def _compute_tax_group_id(self):
self.ensure_one()
taxes = self.taxes_id
self.tax_group_id = taxes[:-1].tax_group_id.id
self.tax_group_id = taxes[-1:].tax_group_id.id

tax_group_id = fields.Many2one(
comodel_name="account.tax.group",
Expand Down Expand Up @@ -50,7 +50,7 @@ def _price_changed(self, vals):
self._event("on_product_price_changed").notify(product)

def write(self, vals):
result = super(ProductTemplate, self).write(vals)
result = super().write(vals)
self._price_changed(vals)
return result

Expand All @@ -60,7 +60,10 @@ class ProductProduct(models.Model):

@api.model
def _price_changed_fields(self):
return {"lst_price", "standard_price", "price", "price_extra"}
return {
"lst_price",
"price_extra",
} | self.product_tmpl_id._price_changed_fields()

def _price_changed(self, vals):
"""Fire the ``on_product_price_changed`` if the price
Expand All @@ -83,8 +86,9 @@ def write(self, vals):
self._price_changed(vals)
return result

@api.model
def create(self, vals):
product = super(ProductProduct, self).create(vals)
product._price_changed(vals)
return product
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
for vals, record in zip(vals_list, records):
record._price_changed(vals)
return records
25 changes: 12 additions & 13 deletions connector_ecommerce/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,24 @@ def _log_canceled_in_backend(self):
for invoice in order.invoice_ids:
invoice.message_post(body=message)

@api.model
def create(self, values):
order = super(SaleOrder, self).create(values)
if values.get("canceled_in_backend"):
order._log_canceled_in_backend()
order._try_auto_cancel()
return order
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
for vals, record in zip(vals_list, records):
if vals.get("canceled_in_backend"):
record._log_canceled_in_backend()
record._try_auto_cancel()
return records

def write(self, values):
result = super(SaleOrder, self).write(values)
result = super().write(values)
if values.get("canceled_in_backend"):
self._log_canceled_in_backend()
self._try_auto_cancel()
return result

def action_cancel(self):
res = super(SaleOrder, self).action_cancel()
res = super().action_cancel()
for sale in self:
# the sales order is canceled => considered as resolved
if sale.canceled_in_backend and not sale.cancellation_resolved:
Expand Down Expand Up @@ -219,8 +220,6 @@ def action_view_parent(self):

def _create_delivery_line(self, carrier, price_unit):
if self.order_line.filtered(lambda r: r.is_delivery):
# skip if we have already a delivery line (created by
# import of order)
# skip if we have already a delivery line (created by import of order)
return
else:
return super(SaleOrder, self)._create_delivery_line(carrier, price_unit)
return super()._create_delivery_line(carrier, price_unit)
2 changes: 1 addition & 1 deletion connector_ecommerce/models/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StockPicking(models.Model):
)

def write(self, vals):
res = super(StockPicking, self).write(vals)
res = super().write(vals)
if vals.get("carrier_tracking_ref"):
for record in self:
self._event("on_tracking_number_added").notify(record)
Expand Down
2 changes: 1 addition & 1 deletion connector_ecommerce/tests/test_invoice_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestInvoiceEvent(common.TransactionCase):
"""Test if the events on the invoice are fired correctly"""

def setUp(self):
super(TestInvoiceEvent, self).setUp()
super().setUp()
self.invoice_model = self.env["account.move"]
partner_model = self.env["res.partner"]
partner = partner_model.create({"name": "Hodor"})
Expand Down
2 changes: 1 addition & 1 deletion connector_ecommerce/tests/test_onchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestOnchange(ComponentRegistry):
"""Test if the onchanges are applied correctly on a sales order"""

def setUp(self):
super(TestOnchange, self).setUp()
super().setUp()
self.collection = self.env["collection.base"]
OnChangeManager._build_component(self.comp_registry)
SaleOrderOnChange._build_component(self.comp_registry)
Expand Down
2 changes: 1 addition & 1 deletion connector_ecommerce/tests/test_picking_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _create_pack_operation(self, product, product_qty, picking_id, **values):
)

def setUp(self):
super(TestPickingEvent, self).setUp()
super().setUp()
self.picking_model = self.env["stock.picking"]
self.sale_model = self.env["sale.order"]
self.sale_line_model = self.env["sale.order.line"]
Expand Down

0 comments on commit 791a828

Please sign in to comment.