From 531f22bb3993b29e2cd5200f50b3320eec02ad33 Mon Sep 17 00:00:00 2001 From: gregoire Date: Sun, 22 May 2016 15:08:51 +0200 Subject: [PATCH] add actions request print and set as printed label --- beesdoo_product/__init__.py | 3 +- beesdoo_product/__openerp__.py | 3 +- beesdoo_product/models/beesdoo_product.py | 36 +++++- beesdoo_product/views/beesdoo_product.xml | 111 +++++++++++------- beesdoo_product/wizard/__init__.py | 1 + .../wizard/label_printing_utils.py | 22 ++++ .../wizard/views/label_printing_utils.xml | 55 +++++++++ 7 files changed, 188 insertions(+), 43 deletions(-) create mode 100644 beesdoo_product/wizard/__init__.py create mode 100644 beesdoo_product/wizard/label_printing_utils.py create mode 100644 beesdoo_product/wizard/views/label_printing_utils.xml diff --git a/beesdoo_product/__init__.py b/beesdoo_product/__init__.py index 0f7cb6b..8d752fb 100644 --- a/beesdoo_product/__init__.py +++ b/beesdoo_product/__init__.py @@ -1,2 +1,3 @@ # -*- coding: utf-8 -*- -import models \ No newline at end of file +import models +import wizard diff --git a/beesdoo_product/__openerp__.py b/beesdoo_product/__openerp__.py index cdf8dd5..c7728aa 100644 --- a/beesdoo_product/__openerp__.py +++ b/beesdoo_product/__openerp__.py @@ -26,8 +26,9 @@ 'data': [ 'data/product_label.xml', 'views/beesdoo_product.xml', + 'wizard/views/label_printing_utils.xml', 'security/ir.model.access.csv', ], # only loaded in demonstration mode 'demo': [], -} \ No newline at end of file +} diff --git a/beesdoo_product/models/beesdoo_product.py b/beesdoo_product/models/beesdoo_product.py index 666c422..566bc95 100644 --- a/beesdoo_product/models/beesdoo_product.py +++ b/beesdoo_product/models/beesdoo_product.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from openerp import models, fields, api from openerp.tools.translate import _ +import datetime class BeesdooProduct(models.Model): _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) + 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.depends('seller_ids', 'seller_ids.date_start') 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) 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): @@ -27,4 +62,3 @@ class BeesdooProductLabel(models.Model): name = fields.Char() type = fields.Selection([('eco', 'Écologique'), ('local', 'Local'), ('fair', 'Équitable'), ('delivery', 'Distribution')]) color_code = fields.Char() - diff --git a/beesdoo_product/views/beesdoo_product.xml b/beesdoo_product/views/beesdoo_product.xml index b829117..1bad7a2 100644 --- a/beesdoo_product/views/beesdoo_product.xml +++ b/beesdoo_product/views/beesdoo_product.xml @@ -1,43 +1,74 @@ - - - - bees.product.template.form - product.template - - - - - - - + + bees.product.template.form + product.template + + + + + + + + + + + + bees.product.template.form2 + product.template + + +
+ +
+
+
+ + bees.product.label.form + beesdoo.product.label + +
+ + + + + +
-
-
- - - bees.product.template.form2 - product.template - - -
- -
-
-
- - - bees.product.label.form - beesdoo.product.label - -
- - - - - -
-
-
-
\ No newline at end of file + + + bees.product + product.template + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/beesdoo_product/wizard/__init__.py b/beesdoo_product/wizard/__init__.py new file mode 100644 index 0000000..183e6cc --- /dev/null +++ b/beesdoo_product/wizard/__init__.py @@ -0,0 +1 @@ +import label_printing_utils diff --git a/beesdoo_product/wizard/label_printing_utils.py b/beesdoo_product/wizard/label_printing_utils.py new file mode 100644 index 0000000..8f784af --- /dev/null +++ b/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() diff --git a/beesdoo_product/wizard/views/label_printing_utils.xml b/beesdoo_product/wizard/views/label_printing_utils.xml new file mode 100644 index 0000000..1adf79c --- /dev/null +++ b/beesdoo_product/wizard/views/label_printing_utils.xml @@ -0,0 +1,55 @@ + + + + Request Label Printing Wizard + label.printing.wizard + +
+ +
+
+ +
+
+ + + Request Label Printing Wizard + label.printing.wizard + +
+ +
+
+ +
+
+ +