Skip to content

Commit

Permalink
[IMP] connector_oxigesti: logic for deprecated field of pricelist item
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC013 committed Jan 2, 2024
1 parent d77e8af commit e61bd5e
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import export_mapper
from . import binder
from . import binding
from . import listener
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright NuoBiT Solutions - Eric Antones <[email protected]>
# Copyright NuoBiT Solutions - Kilian Niubo <[email protected]>
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import api, fields, models
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ def Codigo_Mutua(self, record):

@mapping
def Deprecated(self, record):
if (
self.env.context.get("pricelist_item_deprecated", False)
or not record.active
or not record.product_tmpl_id.active
):
return {"Deprecated": 1}

Check warning on line 71 in connector_oxigesti/models/product_pricelist_item/export_mapper.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_pricelist_item/export_mapper.py#L71

Added line #L71 was not covered by tests
return {"Deprecated": 0}
73 changes: 55 additions & 18 deletions connector_oxigesti/models/product_pricelist_item/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)


from odoo.addons.component.core import Component
from odoo.addons.component.core import AbstractComponent, Component


class ProductPricelistItemBatchExporter(Component):
class ProductPricelistItemBatchExporter(AbstractComponent):
"""Export the Oxigesti Product prices.
For every product in the list, a delayed job is created.
"""

_name = "oxigesti.product.pricelist.item.delayed.batch.exporter"
_inherit = "oxigesti.delayed.batch.exporter"
_apply_on = "oxigesti.product.pricelist.item"
_name = "oxigesti.product.pricelist.item.batch.exporter"

def run(self, domain=None):
def run_common(self, domain=None):
if not domain:
domain = []
# Run the batch synchronization
Expand All @@ -39,20 +37,27 @@ def run(self, domain=None):
binder = self.binder_for(self.model._name)
for p in self.env["res.partner"].search(domain):
partner_external_id = partner_binder.to_external(p, wrap=True)
for pl in p.property_product_pricelist.item_ids.filtered(
lambda x: (
not since_date
or x.write_date > since_date
or p.write_date > since_date
price_list_item = self.env.context.get("pricelist_item_deprecated", False)

Check warning on line 40 in connector_oxigesti/models/product_pricelist_item/exporter.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_pricelist_item/exporter.py#L40

Added line #L40 was not covered by tests
if price_list_item:
price_list_items = self.env["product.pricelist.item"].search(

Check warning on line 42 in connector_oxigesti/models/product_pricelist_item/exporter.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_pricelist_item/exporter.py#L42

Added line #L42 was not covered by tests
[("id", "=", price_list_item)]
)
and p.customer_rank >= p.supplier_rank
and x.applied_on == "1_product"
and x.compute_price == "fixed"
and (
not x.sudo().product_tmpl_id.company_id
or x.sudo().product_tmpl_id.company_id == p.company_id
else:
price_list_items = p.property_product_pricelist.item_ids.filtered(
lambda x: (
not since_date
or x.write_date > since_date
or p.write_date > since_date
)
and p.customer_rank >= p.supplier_rank
and x.applied_on == "1_product"
and x.compute_price == "fixed"
and (
not x.sudo().product_tmpl_id.company_id
or x.sudo().product_tmpl_id.company_id == p.company_id
)
)
):
for pl in price_list_items:
if pl.product_tmpl_id.default_code and partner_external_id:
external_id = [
pl.product_tmpl_id.default_code,
Expand All @@ -75,6 +80,38 @@ def run(self, domain=None):
self._export_record(binding)


class ProductPricelistItemDelayedBatchExporter(Component):
"""Export the Oxigesti Product prices.
For every product in the list, a delayed job is created.
"""

_name = "oxigesti.product.pricelist.item.delayed.batch.exporter"
_inherit = [
"oxigesti.delayed.batch.exporter",
"oxigesti.product.pricelist.item.batch.exporter",
]

def run(self, domain=None):
super().run_common(domain=domain)

Check warning on line 96 in connector_oxigesti/models/product_pricelist_item/exporter.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_pricelist_item/exporter.py#L96

Added line #L96 was not covered by tests


class ProductPricelistItemDirectBatchExporter(Component):
"""Export the Oxigesti Product prices.
For every product in the list, a direct job is created.
"""

_name = "oxigesti.product.pricelist.item.direct.batch.exporter"
_inherit = [
"oxigesti.direct.batch.exporter",
"oxigesti.product.pricelist.item.batch.exporter",
]

def run(self, domain=None):
super().run_common(domain=domain)

Check warning on line 112 in connector_oxigesti/models/product_pricelist_item/exporter.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_pricelist_item/exporter.py#L112

Added line #L112 was not covered by tests


class ProductPricelistItemExporter(Component):
_name = "oxigesti.product.pricelist.item.exporter"
_inherit = "oxigesti.exporter"
Expand Down
23 changes: 23 additions & 0 deletions connector_oxigesti/models/product_pricelist_item/listener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright NuoBiT Solutions - Frank Cespedes <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo.addons.component.core import Component


class ProductPricelistItemListener(Component):
_name = "oxigesti.product.pricelist.item.listener"
_inherit = "oxigesti.event.listener"

_apply_on = "product.pricelist.item"

def on_record_unlink(self, relation):
bindings = relation.oxigesti_bind_ids

Check warning on line 14 in connector_oxigesti/models/product_pricelist_item/listener.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_pricelist_item/listener.py#L14

Added line #L14 was not covered by tests
for backend in bindings.with_context(
pricelist_item_deprecated=relation.id
).backend_id:
partners = bindings.filtered(
lambda x: x.backend_id == backend
).odoo_partner_id
with backend.work_on(bindings._name) as work:
exporter = work.component(usage="direct.batch.exporter")
exporter.run([("id", "=", partners.ids)])

Check warning on line 23 in connector_oxigesti/models/product_pricelist_item/listener.py

View check run for this annotation

Codecov / codecov/patch

connector_oxigesti/models/product_pricelist_item/listener.py#L21-L23

Added lines #L21 - L23 were not covered by tests

0 comments on commit e61bd5e

Please sign in to comment.