Browse Source

[ADD] pos_price_to_weight: choose price field

pull/485/head
Manuel Claeys Bouuaert 5 years ago
parent
commit
58d9c29b56
  1. 1
      pos_price_to_weight/__manifest__.py
  2. 2
      pos_price_to_weight/demo/product_product.xml
  3. 1
      pos_price_to_weight/models/__init__.py
  4. 22
      pos_price_to_weight/models/pos_config.py
  5. 15
      pos_price_to_weight/readme/CONFIGURE.rst
  6. BIN
      pos_price_to_weight/static/description/pos_config_form.png
  7. 7
      pos_price_to_weight/static/src/js/models.js
  8. 27
      pos_price_to_weight/views/view_pos_config.xml

1
pos_price_to_weight/__manifest__.py

@ -17,6 +17,7 @@
'data': [
'data/barcode_rule.xml',
'views/assets.xml',
'views/view_pos_config.xml',
],
'demo': [
'demo/product_product.xml',

2
pos_price_to_weight/demo/product_product.xml

@ -11,6 +11,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="name">Apples (with Price To Weight Barcode)</field>
<field name="barcode">0212345000007</field>
<field name="list_price">1.50</field>
<field name="available_in_pos">True</field>
<field name="to_weight">True</field>
<field name="uom_id" ref="uom.product_uom_kgm"/>
<field name="uom_po_id" ref="uom.product_uom_kgm"/>
</record>

1
pos_price_to_weight/models/__init__.py

@ -1 +1,2 @@
from . import barcode_rule
from . import pos_config

22
pos_price_to_weight/models/pos_config.py

@ -0,0 +1,22 @@
# Copyright 2020 Coop IT Easy - Manuel Claeys Bouuaert
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class PosConfig(models.Model):
_inherit = 'pos.config'
pos_price_to_weight_price_field_id = fields.Many2one(
string="Price To Weight Field",
comodel_name="ir.model.fields",
domain=[("model", "=", "product.product"), ("ttype", "=", "float")],
required=True,
default=lambda x: x._default_pos_price_to_weight_price_field_id(),
)
pos_price_to_weight_price_field_name = fields.Char(
related="pos_price_to_weight_price_field_id.name")
def _default_pos_price_to_weight_price_field_id(self):
return self.env.ref("product.field_product_product__list_price")

15
pos_price_to_weight/readme/CONFIGURE.rst

@ -1,2 +1,15 @@
* Go to 'Point of Sale' / 'Configuration' / 'Barcode Nomenclatures'
* Go to Point of Sale > Configuration > Barcode Nomenclatures
* Edit your barcode rules, according to your barcodes settings
* Go to Point of Sale > Configuration > Point of Sale
* Select the 'Unit Price' field that will be used to convert the price to weight.
.. image:: ../static/description/pos_config_form.png
:width: 800 px
**Note:**
By default, this is the field ``list_price`` that will be used.
If you want to use a custom field, it should be loaded in the javascript file calling
``models.load_fields("product.product", ['my_custom_field']);``

BIN
pos_price_to_weight/static/description/pos_config_form.png

After

Width: 941  |  Height: 153  |  Size: 15 KiB

7
pos_price_to_weight/static/src/js/models.js

@ -27,8 +27,11 @@ odoo.define('pos_price_to_weight.models', function (require) {
}
var quantity = 0;
var price = parseFloat(parsed_code.value) || 0;
if (price !== 0 && product.list_price !== 0){
quantity = price / product.list_price;
var product_price = product[this.config.pos_price_to_weight_price_field_name];
if (price !== 0 && product_price !== 0){
quantity = price / product_price;
}
selectedOrder.add_product(product, {quantity: quantity, merge: false});
return true;

27
pos_price_to_weight/views/view_pos_config.xml

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2018 Coop IT Easy - Manuel Claeys Bouuaert
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="view_pos_config_form" model="ir.ui.view">
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<div id="posbox_reference" position="inside">
<div class="col-xs-12 col-md-6 o_setting_box" id="pos_price_to_weight">
<div class="o_setting_right_pane">
<label for="pos_price_to_weight_price_field_id"/>
<div class="text-muted">
Unit Price field used when converting scanned weight to price.
</div>
<div class="content-group mt16">
<field name="pos_price_to_weight_price_field_id" colspan="4" nolabel="1" options="{'no_create': True}"/>
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>
Loading…
Cancel
Save