diff --git a/pos_pricelist/__init__.py b/pos_pricelist/__init__.py index 8b20599f..9e2b95da 100644 --- a/pos_pricelist/__init__.py +++ b/pos_pricelist/__init__.py @@ -17,3 +17,14 @@ # ############################################################################## from . import models + + +def set_pos_line_taxes(cr, registry): + """Copy the product taxes to the pos.line""" + cr.execute("""insert into pline_tax_rel + select l.id, t.id + from pos_order_line l + join pos_order o on l.order_id = o.id + join product_taxes_rel rel on rel.prod_id = l.product_id + join account_tax t on rel.tax_id = t.id + where t.company_id = o.company_id""") diff --git a/pos_pricelist/__openerp__.py b/pos_pricelist/__openerp__.py index c4654eed..c5106d42 100644 --- a/pos_pricelist/__openerp__.py +++ b/pos_pricelist/__openerp__.py @@ -18,7 +18,7 @@ ############################################################################## { 'name': 'POS Pricelist', - 'version': '1.0.0', + 'version': '1.1.0', 'category': 'Point Of Sale', 'sequence': 1, 'author': "Adil Houmadi @Taktik,Odoo Community Association (OCA)", @@ -34,6 +34,7 @@ New feature for the Point Of Sale: 'data': [ "views/pos_pricelist_template.xml", "views/pos_pricelist_views.xml", + "views/point_of_sale_view.xml" ], 'demo': [ 'demo/pos_pricelist_demo.yml', @@ -41,6 +42,7 @@ New feature for the Point Of Sale: 'qweb': [ 'static/src/xml/pos.xml' ], + 'post_init_hook': "set_pos_line_taxes", 'installable': True, 'application': False, 'auto_install': False, diff --git a/pos_pricelist/migrations/8.0.1.1.0/post-migration.py b/pos_pricelist/migrations/8.0.1.1.0/post-migration.py new file mode 100644 index 00000000..d2a888f9 --- /dev/null +++ b/pos_pricelist/migrations/8.0.1.1.0/post-migration.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Aserti Global Solutions (http://www.aserti.es/). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +__name__ = ("Copy the product taxes to the pos.line") + + +def migrate(cr, version): + cr.execute("""insert into pline_tax_rel + select l.id, t.id + from pos_order_line l + join pos_order o on l.order_id = o.id + join product_taxes_rel rel on rel.prod_id = l.product_id + join account_tax t on rel.tax_id = t.id + where t.company_id = o.company_id""") diff --git a/pos_pricelist/models/__init__.py b/pos_pricelist/models/__init__.py index 6edd473a..e139cc36 100644 --- a/pos_pricelist/models/__init__.py +++ b/pos_pricelist/models/__init__.py @@ -17,3 +17,4 @@ # ############################################################################## from . import pos_pricelist +from . import point_of_sale diff --git a/pos_pricelist/models/point_of_sale.py b/pos_pricelist/models/point_of_sale.py new file mode 100644 index 00000000..494622ca --- /dev/null +++ b/pos_pricelist/models/point_of_sale.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2015 Aserti Global Solutions (http://www.aserti.es/). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + + +from openerp import models, fields, api +# import logging +# _logger = logging.getLogger(__name__) + + +class PosOrderLine(models.Model): + _inherit = "pos.order.line" + + @api.one + @api.depends('tax_ids', 'qty', 'price_unit', + 'product_id', 'discount', 'order_id.partner_id') + def _amount_line_all(self): + price = self.price_unit * (1 - (self.discount or 0.0) / 100.0) + taxes = self.tax_ids.compute_all( + price, self.qty, product=self.product_id, + partner=self.order_id.partner_id) + self.price_subtotal = taxes['total'] + self.price_subtotal_incl = taxes['total_included'] + + tax_ids = fields.Many2many( + 'account.tax', 'pline_tax_rel', 'pos_line_id', 'tax_id', + "Taxes", domain=[('type_tax_use', '=', 'sale')]) + price_subtotal = fields.Float(compute="_amount_line_all", store=True) + price_subtotal_incl = fields.Float(compute="_amount_line_all", store=True) + + +class PosOrder(models.Model): + _inherit = "pos.order" + + @api.model + def _amount_line_tax(self, line): + price = line.price_unit * (1 - (line.discount or 0.0) / 100.0) + taxes = line.tax_ids.compute_all( + price, line.qty, product=line.product_id, + partner=line.order_id.partner_id)['taxes'] + val = 0.0 + for c in taxes: + val += c.get('amount', 0.0) + return val + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/pos_pricelist/static/src/js/models.js b/pos_pricelist/static/src/js/models.js index 35f59be5..cebe78f0 100644 --- a/pos_pricelist/static/src/js/models.js +++ b/pos_pricelist/static/src/js/models.js @@ -295,6 +295,20 @@ function pos_pricelist_models(instance, module) { return OrderlineParent.prototype.get_display_price.apply( this, arguments ); + }, + + export_as_JSON: function() { + var res = OrderlineParent.prototype.export_as_JSON.apply(this, arguments); + var product_tax_ids = this.get_product().taxes_id || []; + var partner = this.order ? this.order.get_client() : null; + if (partner && partner.property_account_position) { + product_tax_ids = + this.pos.db.find_taxes_by_fiscal_position_id( + partner.property_account_position[0], product_tax_ids + ); + } + res["tax_ids"] = [[6, false, product_tax_ids]]; + return res; } }); diff --git a/pos_pricelist/views/point_of_sale_view.xml b/pos_pricelist/views/point_of_sale_view.xml new file mode 100644 index 00000000..7590eff6 --- /dev/null +++ b/pos_pricelist/views/point_of_sale_view.xml @@ -0,0 +1,108 @@ + + + + + + pos.order + pos.order + + + + + + + + + +