Compare commits

...

4 Commits

  1. 41
      beesdoo_product/models/beesdoo_product.py
  2. 3
      beesdoo_product/readme/DESCRIPTION.rst
  3. 11
      beesdoo_product/views/beesdoo_product.xml

41
beesdoo_product/models/beesdoo_product.py

@ -11,6 +11,19 @@ from odoo.tools.translate import _
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
class ResPartner(models.Model):
_inherit = "res.partner"
profit_margin = fields.Float(string="Product Margin [%]")
@api.multi
@api.constrains("profit_margin")
def _check_margin(self):
for product in self:
if product.profit_margin < 0.0:
raise UserError(_("Percentages for Profit Margin must >= 0."))
class BeesdooProduct(models.Model): class BeesdooProduct(models.Model):
_inherit = "product.template" _inherit = "product.template"
@ -59,10 +72,13 @@ class BeesdooProduct(models.Model):
note = fields.Text("Comments") note = fields.Text("Comments")
# S0023 : List_price = Price HTVA, so add a suggested price
list_price = fields.Float(string="exVAT Price")
suggested_price = fields.Float( suggested_price = fields.Float(
string="Suggested exVAT Price", compute="_compute_cost", readOnly=True
string="Suggested Price", compute="_compute_cost", 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
Margin' field in Product Categories (which has a default value).
"""
) )
deadline_for_sale = fields.Integer(string="Deadline for sale(days)") deadline_for_sale = fields.Integer(string="Deadline for sale(days)")
@ -252,12 +268,17 @@ class BeesdooProduct(models.Model):
for product in self: for product in self:
suppliers = product._get_main_supplier_info() suppliers = product._get_main_supplier_info()
if len(suppliers) > 0: if len(suppliers) > 0:
product.suggested_price = (
suppliers[0].price * product.uom_po_id.factor
) * (
1
+ suppliers[0].product_tmpl_id.categ_id.profit_margin / 100
price = suppliers[0].price
profit_margin_supplier = suppliers[0].name.profit_margin
profit_margin_product_category = suppliers[
0
].product_tmpl_id.categ_id.profit_margin
profit_margin = (
profit_margin_supplier or profit_margin_product_category
) )
product.suggested_price = (
price * product.uom_po_id.factor
) * (1 + profit_margin / 100)
class BeesdooScaleCategory(models.Model): class BeesdooScaleCategory(models.Model):
@ -303,13 +324,13 @@ class BeesdooProductCategory(models.Model):
def _check_margin(self): def _check_margin(self):
for product in self: for product in self:
if product.profit_margin < 0.0: if product.profit_margin < 0.0:
raise UserError(_("Percentages for Profit Margin must > 0."))
raise UserError(_("Percentages for Profit Margin must >= 0."))
class BeesdooProductSupplierInfo(models.Model): class BeesdooProductSupplierInfo(models.Model):
_inherit = "product.supplierinfo" _inherit = "product.supplierinfo"
price = fields.Float("exVAT Price")
price = fields.Float("Price")
class BeesdooUOMCateg(models.Model): class BeesdooUOMCateg(models.Model):

3
beesdoo_product/readme/DESCRIPTION.rst

@ -1,2 +1,3 @@
Modification of product module for the needs of beescoop Modification of product module for the needs of beescoop
- SOOO5 - Ajout de label bio/ethique/provenance
- SOOO5 - Adds the label bio/ethique/provenance
- Add a 'Suggested Price' field on products, and a 'Product Margin' field on Partners (Vendors) and Product Categories. The first margin is used if set, otherwise the second margin (which has a default value) is used.

11
beesdoo_product/views/beesdoo_product.xml

@ -164,6 +164,17 @@
</field> </field>
</record> </record>
<record id="beesdoo_product_res_parter_form" model="ir.ui.view">
<field name="name">res.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<group name="purchase" position="inside">
<field name="profit_margin"/>
</group>
</field>
</record>
<record model="ir.ui.view" id="beesdoo_scale_category_list"> <record model="ir.ui.view" id="beesdoo_scale_category_list">
<field name="name">beesdoo.scale.category.list</field> <field name="name">beesdoo.scale.category.list</field>
<field name="model">beesdoo.scale.category</field> <field name="model">beesdoo.scale.category</field>

Loading…
Cancel
Save