@ -12,6 +12,19 @@ from odoo.tools.translate import _
_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 ) :
_inherit = " product.template "
@ -60,10 +73,13 @@ class BeesdooProduct(models.Model):
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 (
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) " )
@ -259,12 +275,17 @@ class BeesdooProduct(models.Model):
for product in self :
suppliers = product . _get_main_supplier_info ( )
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 ) :
@ -310,13 +331,13 @@ class BeesdooProductCategory(models.Model):
def _check_margin ( self ) :
for product in self :
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 ) :
_inherit = " product.supplierinfo "
price = fields . Float ( " exVAT Price" )
price = fields . Float ( " Price " )
class BeesdooUOMCateg ( models . Model ) :