Browse Source

[MERGE][S0011] Infos étiquettes sur l'article author: Samuel et Grégoire

pull/13/head
Thibault Francois 9 years ago
parent
commit
44324f1d7b
  1. 30
      beesdoo_product/models/beesdoo_product.py
  2. 45
      beesdoo_product/views/beesdoo_product.xml

30
beesdoo_product/models/beesdoo_product.py

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from openerp import models, fields, api from openerp import models, fields, api
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp.exceptions import UserError
class BeesdooProduct(models.Model): class BeesdooProduct(models.Model):
_inherit = "product.template" _inherit = "product.template"
@ -12,6 +13,13 @@ class BeesdooProduct(models.Model):
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)
display_unit = fields.Many2one('product.uom', required=True, default=lambda self: self.env.ref('product.product_uom_kgm'))
default_reference_unit = fields.Many2one('product.uom', required=True, default=lambda self: self.env.ref('product.product_uom_kgm'))
display_weight = fields.Float(compute='_get_display_weight', store=True)
total_with_vat = fields.Float(compute='_get_total_with_vat', store=True)
total_with_vat_by_unit = fields.Float(compute='_get_total_with_vat_by_unit', store=True)
@api.one @api.one
@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):
@ -19,7 +27,29 @@ class BeesdooProduct(models.Model):
sellers_ids = self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True) sellers_ids = 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.depends('taxes_id', 'list_price')
def _get_total_with_vat(self):
tax_amount_sum = sum([tax.amount for tax in self.taxes_id])
self.total_with_vat = self.list_price * (100.0 + tax_amount_sum) / 100
@api.one
@api.depends('total_with_vat', 'display_weight', 'weight')
def _get_total_with_vat_by_unit(self):
print self.display_weight, self.total_with_vat, self.weight
if self.display_weight > 0:
self.total_with_vat_by_unit = self.total_with_vat / self.weight
@api.one
@api.depends('weight', 'display_unit')
def _get_display_weight(self):
self.display_weight = self.weight * self.display_unit.factor
@api.one
@api.constrains('display_unit', 'default_reference_unit')
def _unit_same_category(self):
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'))
class BeesdooProductLabel(models.Model): class BeesdooProductLabel(models.Model):
_name = "beesdoo.product.label" _name = "beesdoo.product.label"

45
beesdoo_product/views/beesdoo_product.xml

@ -7,26 +7,47 @@
<field name="model">product.template</field> <field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view" /> <field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="barcode" position="after">
<field name="invoice_policy" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="purchase_method" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="route_ids" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<group name="sale_condition" position="attributes">
<attribute name="invisible">1</attribute>
</group>
<field name="property_account_creditor_price_difference" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<xpath expr="//group[@name='inventory']/.." position="after">
<page string="Étiquette">
<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" />
</group>
<group>
<field name="main_seller_id" />
<field name="eco_label"/> <field name="eco_label"/>
<field name="local_label"/> <field name="local_label"/>
<field name="fair_label"/> <field name="fair_label"/>
<field name="origin_label"/> <field name="origin_label"/>
</field>
</field>
</record>
</group>
</group>
<record model="ir.ui.view" id="beesdoo_product_form2">
<field name="name">bees.product.template.form2</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<div name="weight" position="after">
<field name="main_seller_id" string="Fournisseur Principal" />
</div>
</page>
</xpath>
</field> </field>
</record> </record>
<record model="ir.ui.view" id="beesdoo_product_label_form"> <record model="ir.ui.view" id="beesdoo_product_label_form">
<field name="name">bees.product.label.form</field> <field name="name">bees.product.label.form</field>
<field name="model">beesdoo.product.label</field> <field name="model">beesdoo.product.label</field>

Loading…
Cancel
Save