Browse Source

Add profit margin in product_category

pull/14/head
EliseDup 9 years ago
parent
commit
492c8707fe
  1. 40
      beesdoo_product/models/beesdoo_product.py
  2. 29
      beesdoo_product/views/beesdoo_product.xml

40
beesdoo_product/models/beesdoo_product.py

@ -6,10 +6,10 @@ from openerp.exceptions import UserError
class BeesdooProduct(models.Model):
_inherit = "product.template"
eco_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'eco')])
local_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'local')])
fair_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'fair')])
origin_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'delivery')])
eco_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'eco')])
local_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'local')])
fair_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'fair')])
origin_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'delivery')])
main_seller_id = fields.Many2one('res.partner', compute='_compute_main_seller_id', store=True)
@ -26,15 +26,19 @@ class BeesdooProduct(models.Model):
# S0023 : List_price = Price HTVA, so add a suggested price
list_price = fields.Float(string='exVAT Price')
suggested_price = fields.Float(string='Suggested Price', compute='_get_suggested_price', readOnly = True)
suggested_price = fields.Float(string='Suggested Price', compute='_compute_cost', readOnly=True)
standard_price = fields.Float(compute='_compute_cost')
def _get_main_supplier_info(self):
return self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True)
@api.one
@api.depends('seller_ids', 'seller_ids.date_start')
def _compute_main_seller_id(self):
# Calcule le vendeur associé qui a la date de début la plus récente et plus petite qu’aujourd’hui
sellers_ids = self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True)
sellers_ids = self._get_main_supplier_info() # self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True)
self.main_seller_id = sellers_ids and sellers_ids[0].name or False
@api.one
@api.depends('taxes_id', 'list_price', 'taxes_id.amount', 'taxes_id.tax_group_id', 'total_with_vat', 'display_weight', 'weight')
def _get_total(self):
@ -57,10 +61,15 @@ class BeesdooProduct(models.Model):
raise UserError(_('Reference Unit and Display Unit should belong to the same category'))
@api.one
@api.depends('list_price')
def _get_suggested_price(self):
self.suggested_price = 1000.0
@api.depends('seller_ids')
def _compute_cost(self):
suppliers = self._get_main_supplier_info()
if(len(suppliers) > 0):
self.standard_price = suppliers[0].price
self.suggested_price = (suppliers[0].price)* (1 + suppliers[0].product_tmpl_id.categ_id.profit_margin / 100)
class BeesdooProductLabel(models.Model):
_name = "beesdoo.product.label"
@ -68,3 +77,14 @@ class BeesdooProductLabel(models.Model):
type = fields.Selection([('eco', 'Écologique'), ('local', 'Local'), ('fair', 'Équitable'), ('delivery', 'Distribution')])
color_code = fields.Char()
class BeesdooProductCategory(models.Model):
_inherit = "product.category"
profit_margin = fields.Float(default = '10.0', string = "Product Margin [%]")
@api.one
@api.constrains('profit_margin')
def _check_margin(self):
if (self.profit_margin < 0.0):
raise UserError(_('Percentages for Profit Margin must > 0.'))

29
beesdoo_product/views/beesdoo_product.xml

@ -1,14 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="beesdoo_product_form">
<field name="name">bees.product.template.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="arch" type="xml">
<field name="list_price" position="after">
<field name="suggested_price" widget='monetary' options="{'currency_field': 'currency_id'}"/>
<field name="suggested_price" widget='monetary'
options="{'currency_field': 'currency_id'}" />
</field>
<field name="invoice_policy" position="attributes">
<attribute name="invisible">1</attribute>
@ -54,7 +53,6 @@
</field>
</record>
<record model="ir.ui.view" id="beesdoo_product_label_form">
<field name="name">bees.product.label.form</field>
<field name="model">beesdoo.product.label</field>
@ -68,4 +66,27 @@
</form>
</field>
</record>
<record model="ir.ui.view" id="beesdoo_product_category_list">
<field name="name">beesdoo.product.category.list</field>
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_list_view" />
<field name="arch" type="xml">
<field name="complete_name" position="after">
<field name="profit_margin"></field>
</field>
</field>
</record>
<record model="ir.ui.view" id="beesdoo_product_category_form">
<field name="name">beesdoo.product.category.form</field>
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view" />
<field name="arch" type="xml">
<field name="parent_id" position="after">
<field name="profit_margin"></field>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save