Browse Source

[ADD] : - add support for price with taxes, new option is introduced in the POS config to let the user show price with taxes in product widget.

- the UI is updated when we change the customer in order to adapt the prices
- the computation take in account the pricelist and the fiscal position of the customer
pull/39/head
Adil Houmadi 10 years ago
parent
commit
cd4d2508ee
  1. 1
      pos_pricelist/__init__.py
  2. 4
      pos_pricelist/__openerp__.py
  3. 19
      pos_pricelist/models/__init__.py
  4. 27
      pos_pricelist/models/pos_pricelist.py
  5. 50
      pos_pricelist/static/src/js/db.js
  6. 68
      pos_pricelist/static/src/js/models.js
  7. 17
      pos_pricelist/static/src/js/widgets.js
  8. 30
      pos_pricelist/static/src/xml/pos.xml
  9. 15
      pos_pricelist/views/pos_pricelist_views.xml

1
pos_pricelist/__init__.py

@ -16,3 +16,4 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import models

4
pos_pricelist/__openerp__.py

@ -33,10 +33,14 @@ New feature for the Point Of Sale:
],
'data': [
"views/pos_pricelist_template.xml",
"views/pos_pricelist_views.xml",
],
'demo': [
'demo/pos_pricelist_demo.yml',
],
'qweb': [
'static/src/xml/pos.xml'
],
'installable': True,
'application': False,
'auto_install': False,

19
pos_pricelist/models/__init__.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
##############################################################################
# Point Of Sale - Pricelist for POS Odoo
# Copyright (C) 2015 Taktik (http://www.taktik.be)
# @author Adil Houmadi <ah@taktik.be>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import pos_pricelist

27
pos_pricelist/models/pos_pricelist.py

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
##############################################################################
# Point Of Sale - Pricelist for POS Odoo
# Copyright (C) 2015 Taktik (http://www.taktik.be)
# @author Adil Houmadi <ah@taktik.be>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields
class PosPriceListConfig(models.Model):
_inherit = 'pos.config'
display_price_with_taxes = fields.Boolean(
string='Price With Taxes',
help="Display Prices with taxes on POS"
)

50
pos_pricelist/static/src/js/db.js

@ -1,20 +1,20 @@
/******************************************************************************
* Point Of Sale - Pricelist for POS Odoo
* Copyright (C) 2014 Taktik (http://www.taktik.be)
* @author Adil Houmadi <ah@taktik.be>
*
* 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 <http://www.gnu.org/licenses/>.
*
******************************************************************************/
* Point Of Sale - Pricelist for POS Odoo
* Copyright (C) 2014 Taktik (http://www.taktik.be)
* @author Adil Houmadi <ah@taktik.be>
*
* 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 <http://www.gnu.org/licenses/>.
*
******************************************************************************/
function pos_pricelist_db(instance, module) {
module.PosDB = module.PosDB.extend({
@ -156,6 +156,24 @@ function pos_pricelist_db(instance, module) {
}
}
return taxes;
},
add_products: function (products) {
this._super(products);
var pos = posmodel.pos_widget.pos;
for (var id in this.product_by_id) {
if (this.product_by_id.hasOwnProperty(id)) {
var product = this.product_by_id[id];
var orderline = new openerp.point_of_sale.Orderline({}, {
pos: pos,
order: null,
product: product,
price: product.price
});
var prices = orderline.get_all_prices();
this.product_by_id[id].price_with_taxes
= prices['priceWithTax']
}
}
}
})
}

68
pos_pricelist/static/src/js/models.js

@ -1,20 +1,20 @@
/******************************************************************************
* Point Of Sale - Pricelist for POS Odoo
* Copyright (C) 2014 Taktik (http://www.taktik.be)
* @author Adil Houmadi <ah@taktik.be>
*
* 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 <http://www.gnu.org/licenses/>.
*
******************************************************************************/
* Point Of Sale - Pricelist for POS Odoo
* Copyright (C) 2014 Taktik (http://www.taktik.be)
* @author Adil Houmadi <ah@taktik.be>
*
* 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 <http://www.gnu.org/licenses/>.
*
******************************************************************************/
function pos_pricelist_models(instance, module) {
var _t = instance.web._t;
@ -137,10 +137,10 @@ function pos_pricelist_models(instance, module) {
initialize: function (attr, options) {
this.constructor.__super__.initialize.apply(this, arguments);
this.manuel_price = false;
if (options.product !== undefined) {
var qty = this.compute_qty(options.order, options.product);
var partner = options.order.get_client();
var product = options.product;
if (this.product !== undefined) {
var qty = this.compute_qty(this.order, this.product);
var partner = this.order ? this.order.get_client() : null;
var product = this.product;
var db = this.pos.db;
var price = this.pos.pricelist_engine.compute_price_all(
db, product, partner, qty
@ -194,7 +194,7 @@ function pos_pricelist_models(instance, module) {
var taxdetail = {};
// Add by pos_pricelist
var partner = this.order.get_client();
var partner = this.order ? this.order.get_client() : null;
var fiscal_position_taxes = [];
if (partner && partner.property_account_position) {
fiscal_position_taxes =
@ -310,7 +310,7 @@ function pos_pricelist_models(instance, module) {
compute_qty: function (order, product) {
var qty = 1;
var orderlines = [];
if (order.get('orderLines').models !== undefined) {
if (order && order.get('orderLines').models !== undefined) {
orderlines = order.get('orderLines').models;
}
for (var i = 0; i < orderlines.length; i++) {
@ -502,7 +502,7 @@ function pos_pricelist_models(instance, module) {
var price_limit = price;
price = price * (1.0 + (rule['price_discount']
? rule['price_discount']
: 0.0))
: 0.0));
if (rule['price_round']) {
price = parseFloat(price.toFixed(
Math.ceil(Math.log(1.0 / rule['price_round'])
@ -540,9 +540,28 @@ function pos_pricelist_models(instance, module) {
for (var i = 0, len = product_list_ui.length; i < len; i++) {
var product_ui = product_list_ui[i];
var product_id = $(product_ui).data('product-id');
var product = db.get_product_by_id(product_id);
// price which computed via pricelist
var product = $.extend({}, db.get_product_by_id(product_id));
var price = this.compute_price_all(db, product, partner, 1);
if (price !== false && price !== 0.0) {
if (this.pos.config.display_price_with_taxes) {
// create a fake order in order to get price
// for this customer
var order = new module.Order({pos: this.pos});
order.set_client(partner);
var orderline = new openerp.point_of_sale.Orderline({},
{
pos: this.pos,
order: order,
product: product,
price: price
}
);
// reset the sequence
this.pos.pos_session.sequence_number--;
var prices = orderline.get_all_prices();
price = prices['priceWithTax'];
}
price = round_di(parseFloat(price)
|| 0, this.pos.dp['Product Price']);
price = this.pos_widget.format_currency(price);
@ -571,7 +590,6 @@ function pos_pricelist_models(instance, module) {
}
}
});
/**
* show error
* @param context

17
pos_pricelist/static/src/js/widgets.js

@ -38,6 +38,21 @@ function pos_pricelist_widgets(instance, module) {
: false;
this.pos.pricelist_engine.update_products_ui(partner);
}
})
});
instance.point_of_sale.ProductListWidget.include({
init: function (parent, options) {
this._super(parent, options);
this.display_price_with_taxes = false;
if (
posmodel
&& posmodel.config
&& posmodel.config.display_price_with_taxes
) {
this.display_price_with_taxes
= posmodel.config.display_price_with_taxes
}
}
});
}

30
pos_pricelist/static/src/xml/pos.xml

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="Product">
<t t-jquery=".product-img" t-operation="replace">
<div class="product-img">
<img t-att-src='image_url' />
<t t-if="!product.to_weight">
<span class="price-tag">
<t t-if="widget.display_price_with_taxes">
<t t-esc="widget.format_currency(product.price_with_taxes,'Product Price')"/>
</t>
<t t-if="!widget.display_price_with_taxes">
<t t-esc="widget.format_currency(product.price,'Product Price')"/>
</t>
</span>
</t>
<t t-if="product.to_weight">
<span class="price-tag">
<t t-if="widget.display_price_with_taxes">
<t t-esc="widget.format_currency(product.price_with_taxes,'Product Price')+'/Kg'"/>
</t>
<t t-if="!widget.display_price_with_taxes">
<t t-esc="widget.format_currency(product.price,'Product Price')+'/Kg'"/>
</t>
</span>
</t>
</div>
</t>
</t>
</templates>

15
pos_pricelist/views/pos_pricelist_views.xml

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_pos_config_form_pos_pricelist" model="ir.ui.view">
<field name="name">view.pos.config.form.pos.pricelist</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.view_pos_config_form"/>
<field name="arch" type="xml">
<field name="iface_big_scrollbars" position="after">
<field name="display_price_with_taxes"/>
</field>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save