Browse Source

[MERGE][S0023] Articles: Prix htva et prix de vente suggéré automatique

pull/14/head
Thibault Francois 8 years ago
parent
commit
b2f2b287b8
  1. 40
      beesdoo_product/models/beesdoo_product.py
  2. 133
      beesdoo_product/views/beesdoo_product.xml

40
beesdoo_product/models/beesdoo_product.py

@ -7,10 +7,10 @@ import uuid
class BeesdooProduct(models.Model): class BeesdooProduct(models.Model):
_inherit = "product.template" _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) main_seller_id = fields.Many2one('res.partner', compute='_compute_main_seller_id', store=True)
@ -27,6 +27,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(string='Suggested exVAT Price', compute='_compute_cost', readOnly=True)
def _get_main_supplier_info(self):
return self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True)
@api.one @api.one
def generate_barcode(self): def generate_barcode(self):
print 'generate barcode', self.barcode, self.barcode == '' print 'generate barcode', self.barcode, self.barcode == ''
@ -45,7 +52,7 @@ class BeesdooProduct(models.Model):
@api.depends('seller_ids', 'seller_ids.date_start') @api.depends('seller_ids', 'seller_ids.date_start')
def _compute_main_seller_id(self): 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 # 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 self.main_seller_id = sellers_ids and sellers_ids[0].name or False
@api.one @api.one
@ -70,6 +77,13 @@ class BeesdooProduct(models.Model):
if self.display_unit.category_id != self.default_reference_unit.category_id: if self.display_unit.category_id != self.default_reference_unit.category_id:
raise UserError(_('Reference Unit and Display Unit should belong to the same category')) raise UserError(_('Reference Unit and Display Unit should belong to the same category'))
@api.one
@api.depends('seller_ids')
def _compute_cost(self):
suppliers = self._get_main_supplier_info()
if(len(suppliers) > 0):
self.suggested_price = (suppliers[0].price * self.uom_po_id.factor)* (1 + suppliers[0].product_tmpl_id.categ_id.profit_margin / 100)
class BeesdooProductLabel(models.Model): class BeesdooProductLabel(models.Model):
_name = "beesdoo.product.label" _name = "beesdoo.product.label"
@ -77,3 +91,19 @@ class BeesdooProductLabel(models.Model):
type = fields.Selection([('eco', 'Écologique'), ('local', 'Local'), ('fair', 'Équitable'), ('delivery', 'Distribution')]) type = fields.Selection([('eco', 'Écologique'), ('local', 'Local'), ('fair', 'Équitable'), ('delivery', 'Distribution')])
color_code = fields.Char() 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.'))
class BeesdooProductSupplierInfo(models.Model):
_inherit = "product.supplierinfo"
price = fields.Float('exVAT Price')

133
beesdoo_product/views/beesdoo_product.xml

@ -1,70 +1,105 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <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="barcode" position="after">
<button string="Generate Barcode" name="generate_barcode" type="object" attrs="{'invisible' : [('barcode','!=',False)]}" /> />
</field>
<field name="invoice_policy" position="attributes">
<attribute name="invisible">1</attribute>
<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="barcode" position="after">
<button string="Generate Barcode" name="generate_barcode" type="object" attrs="{'invisible' : [('barcode','!=',False)]}" /> />
</field>
<field name="list_price" position="after">
<field name="suggested_price" widget='monetary' options="{'currency_field': 'currency_id'}" />
</field>
<field name="invoice_policy" position="attributes">
<attribute name="invisible">1</attribute>
</field> </field>
<field name="purchase_method" position="attributes"> <field name="purchase_method" position="attributes">
<attribute name="invisible">1</attribute>
<attribute name="invisible">1</attribute>
</field> </field>
<field name="route_ids" position="attributes"> <field name="route_ids" position="attributes">
<attribute name="invisible">1</attribute>
<attribute name="invisible">1</attribute>
</field> </field>
<group name="sale_condition" position="attributes"> <group name="sale_condition" position="attributes">
<attribute name="invisible">1</attribute>
<attribute name="invisible">1</attribute>
</group> </group>
<field name="property_account_creditor_price_difference" position="attributes">
<attribute name="invisible">1</attribute>
<field name="property_account_creditor_price_difference"
position="attributes">
<attribute name="invisible">1</attribute>
</field> </field>
<xpath expr="//group[@name='inventory']/.." position="after">
<xpath expr="//group[@name='inventory']/.." position="after">
<page string="Label"> <page string="Label">
<group>
<group name="label">
<field name="total_with_vat"/>
<field name="display_weight"/>
<field name="display_unit" />
<field name="default_reference_unit"/>
<field name="total_with_vat_by_unit" />
<field name="total_deposit" />
</group>
<group>
<field name="main_seller_id" />
<field name="eco_label"/>
<field name="local_label"/>
<field name="fair_label"/>
<field name="origin_label"/>
<field name="label_to_be_printed"/>
<group>
<group name="label">
<field name="total_with_vat"/>
<field name="display_weight"/>
<field name="display_unit" />
<field name="default_reference_unit"/>
<field name="total_with_vat_by_unit" />
<field name="total_deposit" />
</group>
<group>
<field name="main_seller_id" />
<field name="eco_label"/>
<field name="local_label"/>
<field name="fair_label"/>
<field name="origin_label"/>
<field name="label_to_be_printed"/>
<field name="label_last_printed"/> <field name="label_last_printed"/>
</group>
</group>
</group> </group>
<group> <group>
<field name="note" /> <field name="note" />
</group> </group>
</page> </page>
</xpath> </xpath>
</field>
</record>
</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>
<field name="arch" type="xml">
<form>
<group>
<field name="name" />
<field name="type" />
<field name="color_code" />
</group>
</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>
<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>
<field name="arch" type="xml">
<form>
<group>
<field name="name" />
<field name="type" />
<field name="color_code" />
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="beesdoo_product_supplierinfo_tree_view">
<field name="name">beesdoo.product.supplierinfo.tree</field>
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_tree_view" />
<field name="arch" type="xml">
<field name="price" position="replace">
<field name="price"></field>
</field>
</field>
</record>
</odoo> </odoo>
Loading…
Cancel
Save