Browse Source

[IMP] allow srucharge of orderlines loading

pull/378/head
Pierrick Brun 6 years ago
committed by OCA-git-bot
parent
commit
967d4da0a8
  1. 2
      pos_order_mgmt/models/pos_order.py
  2. 1
      pos_order_mgmt/readme/CONTRIBUTORS.rst
  3. 48
      pos_order_mgmt/static/src/js/widgets.js

2
pos_order_mgmt/models/pos_order.py

@ -104,7 +104,7 @@ class PosOrder(models.Model):
def _prepare_done_order_payment_for_pos(self, payment_line):
self.ensure_one()
return {
'statement_id': payment_line.statement_id.id,
'journal_id': payment_line.journal_id.id,
'amount': payment_line.amount,
}

1
pos_order_mgmt/readme/CONTRIBUTORS.rst

@ -1,3 +1,4 @@
* David Vidal <david.vidal@tecnativa.com>
* Sylvain LE GAL (https://twitter.com/legalsylvain)
* Carlos Martínez <carlos@domatix.com>
* Pierrick Brun <pierrick.brun@akretion.com>

48
pos_order_mgmt/static/src/js/widgets.js

@ -208,26 +208,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
}
// Set order lines
var orderLines = order_data.line_ids || order_data.lines || [];
_.each(orderLines, function (orderLine) {
var line = orderLine;
// In case of local data
if (line.length === 3) {
line = line[2];
}
var product = self.pos.db.get_product_by_id(line.product_id);
// Check if product are available in pos
if (_.isUndefined(product)) {
self.unknown_products.push(String(line.product_id));
} else {
// Create a new order line
order.add_product(product, {
price: line.price_unit,
quantity: order_data.return ? line.qty * -1 : line.qty,
discount: line.discount,
merge: false,
});
}
});
self._prepare_orderlines_from_order_data(order, order_data, orderLines);
if (order_data.return) {
order.return = true;
// A credit note should be emited if there was an invoice
@ -235,6 +216,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
// We'll refunded orders once they are synced
order.returned_order_id = order_data.id || order_data.name;
order.origin_name = order_data.pos_reference || order.returned_order_id;
order.trigger('change');
return order;
}
if (order_data.returned_order_id) {
@ -250,7 +232,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
line = line[2];
}
_.each(self.pos.cashregisters, function (cashregister) {
if (cashregister.id === line.statement_id) {
if (cashregister.journal.id === line.journal_id) {
if (line.amount > 0) {
// If it is not change
order.add_paymentline(cashregister);
@ -261,6 +243,28 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
});
return order;
},
_prepare_orderlines_from_order_data: function(order, order_data, orderLines) {
var self = this;
_.each(orderLines, function(line) {
// In case of local data
if (line.length === 3) {
line = line[2];
}
var product = self.pos.db.get_product_by_id(line.product_id);
// Check if product are available in pos
if (_.isUndefined(product)) {
self.unknown_products.push(String(line.product_id));
} else {
// Create a new order line
order.add_product(product, {
price: line.price_unit,
quantity: order_data.return ? line.qty * -1 : line.qty,
discount: line.discount,
merge: false,
});
}
});
},
load_order: function (order_id, action) {
this.unknown_products = [];
@ -270,7 +274,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
method: 'load_done_order_for_pos',
args: [order_id],
}).then(function (order_data) {
self.gui.show_screen('orderlist');
self.gui.back();
var correct_order_print = true;
if (action === 'return') {
order_data.return = true;

Loading…
Cancel
Save