Skip to content

Commit

Permalink
[REF] search product_code -> product_main_seller
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-champonnois committed Sep 27, 2022
1 parent 5fa13cc commit ed6a31c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 35 deletions.
27 changes: 0 additions & 27 deletions beesdoo_product/models/beesdoo_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@ class BeesdooProduct(models.Model):
translate=True,
)

top_supplierinfo_id = fields.Many2one(
comodel_name="product.supplierinfo",
compute="_compute_main_seller_id",
store=True,
)
main_seller_id = fields.Many2one(
string="Main Seller",
comodel_name="res.partner",
related="top_supplierinfo_id.name",
)
main_seller_id_product_code = fields.Char(
string="Main Seller Product Code",
related="top_supplierinfo_id.product_code",
)

display_unit = fields.Many2one("uom.uom")
default_reference_unit = fields.Many2one("uom.uom")
display_weight = fields.Float(
Expand Down Expand Up @@ -164,18 +149,6 @@ def generate_barcode(self):
_logger.info("barcode :", bc)
self.barcode = bc

@api.multi
@api.depends("seller_ids", "seller_ids.date_start")
def _compute_main_seller_id(self):
for product in self:
# todo english code Calcule le vendeur associé qui a la date de
# début la plus récente et plus petite qu’aujourd’hui fixme
# could product.main_seller_id be used instead? it seems that
# “seller” and “supplier” are used interchangeably in this
# class. is this on purpose?
sellers_ids = product._get_main_supplier_info()
product.top_supplierinfo_id = sellers_ids and sellers_ids[0] or False

@api.multi
@api.depends(
"taxes_id",
Expand Down
16 changes: 12 additions & 4 deletions product_main_supplier/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
class ProductTemplate(models.Model):
_inherit = "product.template"

main_seller_id = fields.Many2one(
"res.partner",
string="Main Seller",
top_supplierinfo_id = fields.Many2one(
comodel_name="product.supplierinfo",
compute="_compute_main_seller_id",
store=True,
)
main_seller_id = fields.Many2one(
string="Main Seller",
comodel_name="res.partner",
related="top_supplierinfo_id.name",
)
main_seller_id_product_code = fields.Char(
string="Main Seller Product Code",
related="top_supplierinfo_id.product_code",
)

@api.multi
@api.depends("seller_ids", "seller_ids.date_start")
Expand All @@ -25,7 +33,7 @@ def _compute_main_seller_id(self):
# “seller” and “supplier” are used interchangeably in this
# class. is this on purpose?
sellers_ids = product._get_main_supplier_info()
product.main_seller_id = sellers_ids and sellers_ids[0].name or False
product.top_supplierinfo_id = sellers_ids and sellers_ids[0] or False

def _get_main_supplier_info(self):
# fixme this function either returns a supplier or a collection.
Expand Down
5 changes: 4 additions & 1 deletion product_main_supplier/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Add a main supplier
- Add a main supplier
- Allow searching a product given the product reference of the main
supplier (also known as the `product_code` of the `product.supplierinfo`
object).
1 change: 1 addition & 0 deletions product_main_supplier/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use either "seller" or "supplier", not both.
1 change: 1 addition & 0 deletions product_main_supplier/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_search_main_seller_product_code
18 changes: 18 additions & 0 deletions product_main_supplier/views/product_template_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_template_search_view" model="ir.ui.view">
<field name="name">product.template.main.seller.search</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_search_view" />
<field name="arch" type="xml">
<field name="name" position="after">
<field
name="main_seller_id_product_code"
string="Main Seller Product Code"
/>
<field name="main_seller_id" string="Main Seller" />
</field>
</field>
</record>

</odoo>
4 changes: 2 additions & 2 deletions sale_suggested_price/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ProductTemplate(models.Model):
suggested_price = fields.Float(
string="Suggested Price",
compute="_compute_suggested_price",
readOnly=True,
readonly=True,
help="""
This field computes a suggested price based on the 'Product Margin'
field on Partners (Vendors), if it's set, or otherwise on the 'Product
Expand Down Expand Up @@ -43,7 +43,7 @@ def calculate_suggested_price(self, price=None):
suggested_price_reference = (
self.env["ir.config_parameter"]
.sudo()
.get_param("beesdoo_product.suggested_price_reference")
.get_param("sale_suggested_price.suggested_price_reference")
)
supplier = self._get_main_supplier_info()
if not supplier:
Expand Down
1 change: 0 additions & 1 deletion sale_suggested_price/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from . import test_search_main_seller_product_code
from . import test_suggested_price

0 comments on commit ed6a31c

Please sign in to comment.