Browse Source

add actions request print and set as printed label

pull/12/head
gregoire 9 years ago
parent
commit
531f22bb39
  1. 1
      beesdoo_product/__init__.py
  2. 1
      beesdoo_product/__openerp__.py
  3. 36
      beesdoo_product/models/beesdoo_product.py
  4. 109
      beesdoo_product/views/beesdoo_product.xml
  5. 1
      beesdoo_product/wizard/__init__.py
  6. 22
      beesdoo_product/wizard/label_printing_utils.py
  7. 55
      beesdoo_product/wizard/views/label_printing_utils.xml

1
beesdoo_product/__init__.py

@ -1,2 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import models import models
import wizard

1
beesdoo_product/__openerp__.py

@ -26,6 +26,7 @@
'data': [ 'data': [
'data/product_label.xml', 'data/product_label.xml',
'views/beesdoo_product.xml', 'views/beesdoo_product.xml',
'wizard/views/label_printing_utils.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',
], ],
# only loaded in demonstration mode # only loaded in demonstration mode

36
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 _
import datetime
class BeesdooProduct(models.Model): class BeesdooProduct(models.Model):
_inherit = "product.template" _inherit = "product.template"
@ -12,6 +13,30 @@ 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)
label_to_be_printed = fields.Boolean('Print label?')
label_last_printed = fields.Datetime('Label last printed on')
@api.one
@api.depends('weight', 'display_unit')
def get_display_weight(self):
if self.display_unit:
self.display_weight = self.weight * self.display_unit.factor
@api.one
def get_total_with_vat(self):
tax_amount_sum = 0.0
if hasattr(self, 'taxes_id'):
for tax in self.taxes_id:
tax_amount_sum = tax_amount_sum + tax.amount
self.total_with_vat = self.list_price * (100.0 + tax_amount_sum) / 100
@api.one
def get_total_with_vat_by_unit(self):
if self.display_weight > 0:
self.total_with_vat_by_unit = self.total_with_vat / self.weight
@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,6 +44,16 @@ 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
def _request_label_printing(self):
print("request_printing")
self.label_to_be_printed = True
@api.one
def _set_label_as_printed(self):
self.label_to_be_printed = False
self.label_last_printed = datetime.datetime.now()
class BeesdooProductLabel(models.Model): class BeesdooProductLabel(models.Model):
@ -27,4 +62,3 @@ class BeesdooProductLabel(models.Model):
name = fields.Char() name = fields.Char()
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()

109
beesdoo_product/views/beesdoo_product.xml

@ -1,43 +1,74 @@
<?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">
<field name="eco_label" />
<field name="local_label" />
<field name="fair_label" />
<field name="origin_label" />
<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">
<field name="eco_label" />
<field name="local_label" />
<field name="fair_label" />
<field name="origin_label" />
</field>
</field>
</record>
<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>
</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> </field>
</field>
</record>
<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>
</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>
<record model="ir.ui.view" id="product_template_form_view">
<field name="name">bees.product</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='inventory']/.." position="after">
<page string="Price tag">
<group>
<field name="label_to_be_printed"/>
<field name="label_last_printed"/>
</group>
<group name="label" col="4">
<group col="2">
<separator string="Amount" colspan="4"/>
<field name="display_weight"/>
<field name="display_unit"/>
<field name="default_reference_unit"/>
<separator string="Price" colspan="4"/>
<field name="total_with_vat"/>
<field name="total_with_vat_by_unit"/>
</group>
<group col="2">
<separator string="Bobo-level" colspan="4"/>
<field name="eco_label"/>
<field name="local_label"/>
<field name="fair_label"/>
<field name="origin_label"/>
<separator string="Origin" colspan="4"/>
<field name="main_seller_id"/>
</group>
</group>
</page>
</xpath>
</field>
</record>
</odoo> </odoo>

1
beesdoo_product/wizard/__init__.py

@ -0,0 +1 @@
import label_printing_utils

22
beesdoo_product/wizard/label_printing_utils.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api
class RequestLabelPrintingWizard(models.TransientModel):
_name = 'label.printing.wizard'
def _get_selected_products(self):
return self.env.context['active_ids']
product_ids = fields.Many2many('product.template', default=_get_selected_products)
@api.one
def request_printing(self):
for product in self.product_ids:
product._request_label_printing()
@api.one
def set_as_printed(self):
for product in self.product_ids:
product._set_label_as_printed()

55
beesdoo_product/wizard/views/label_printing_utils.xml

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="printing_label_request_wizard" model="ir.ui.view">
<field name="name">Request Label Printing Wizard</field>
<field name="model">label.printing.wizard</field>
<field name="arch" type="xml">
<form>
<field name="product_ids" />
<footer>
<button
type="object"
name="request_printing"
string="Demander l'impression d'un label"
class="oe_highlight" />
<button special="cancel" string="Annuler" />
</footer>
</form>
</field>
</record>
<act_window name="Request label printing"
res_model="label.printing.wizard"
src_model="product.template"
view_mode="form"
target="new"
view_id="printing_label_request_wizard"
key2="client_action_multi"
id="beesdoo_product_action_request_label_printing"
/>
<record id="set_label_as_printed_wizard" model="ir.ui.view">
<field name="name">Request Label Printing Wizard</field>
<field name="model">label.printing.wizard</field>
<field name="arch" type="xml">
<form>
<field name="product_ids" />
<footer>
<button
type="object"
name="set_as_printed"
string="Marquer les labels comme imprimés"
class="oe_highlight" />
<button special="cancel" string="Annuler" />
</footer>
</form>
</field>
</record>
<act_window name="Set label as printed"
res_model="label.printing.wizard"
src_model="product.template"
view_mode="form"
view_id="set_label_as_printed_wizard"
target="new"
key2="client_action_multi"
id="beesdoo_product_action_set_label_as_printed"
/>
</odoo>
Loading…
Cancel
Save