Browse Source

[MIG] pos_order_mgmt: Migration to 13.0

pull/397/head
AmmarOfficewala 5 years ago
parent
commit
c40de4fa58
  1. 1
      pos_order_mgmt/README.rst
  2. 2
      pos_order_mgmt/__manifest__.py
  3. 18
      pos_order_mgmt/models/pos_order.py
  4. 1
      pos_order_mgmt/readme/CONTRIBUTORS.rst
  5. 35
      pos_order_mgmt/static/src/js/widgets.js
  6. 14
      pos_order_mgmt/tests/test_module.py

1
pos_order_mgmt/README.rst

@ -115,6 +115,7 @@ Contributors
* Carlos Martínez <carlos@domatix.com> * Carlos Martínez <carlos@domatix.com>
* Pierrick Brun <pierrick.brun@akretion.com> * Pierrick Brun <pierrick.brun@akretion.com>
* Iván Todorovich <ivan.todorovich@druidoo.io> * Iván Todorovich <ivan.todorovich@druidoo.io>
* Ammar Officewala <https://twitter.com/AmmarOfficewala>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~

2
pos_order_mgmt/__manifest__.py

@ -5,7 +5,7 @@
{ {
'name': 'POS Frontend Orders Management', 'name': 'POS Frontend Orders Management',
'summary': 'Manage old POS Orders from the frontend', 'summary': 'Manage old POS Orders from the frontend',
'version': '12.0.1.0.3',
'version': '13.0.1.0.0',
'category': 'Point of Sale', 'category': 'Point of Sale',
'author': 'GRAP, ' 'author': 'GRAP, '
'Tecnativa, ' 'Tecnativa, '

18
pos_order_mgmt/models/pos_order.py

@ -30,13 +30,11 @@ class PosOrder(models.Model):
string='Refund Orders Quantity', string='Refund Orders Quantity',
) )
@api.multi
@api.depends('refund_order_ids') @api.depends('refund_order_ids')
def _compute_refund_order_qty(self): def _compute_refund_order_qty(self):
for order in self: for order in self:
order.refund_order_qty = len(order.refund_order_ids) order.refund_order_qty = len(order.refund_order_ids)
@api.multi
def action_view_refund_orders(self): def action_view_refund_orders(self):
self.ensure_one() self.ensure_one()
@ -50,12 +48,9 @@ class PosOrder(models.Model):
action['domain'] = [('id', 'in', self.refund_order_ids.ids)] action['domain'] = [('id', 'in', self.refund_order_ids.ids)]
return action return action
@api.multi
def refund(self): def refund(self):
return super(PosOrder, self.with_context(refund=True)).refund() return super(PosOrder, self.with_context(refund=True)).refund()
@api.multi
@api.returns('self', lambda value: value.id)
def copy(self, default=None): def copy(self, default=None):
self.ensure_one() self.ensure_one()
order = super().copy(default=default) order = super().copy(default=default)
@ -101,7 +96,6 @@ class PosOrder(models.Model):
return self.search_read( return self.search_read(
condition, field_names, limit=config.iface_load_done_order_max_qty) condition, field_names, limit=config.iface_load_done_order_max_qty)
@api.multi
def _prepare_done_order_for_pos(self): def _prepare_done_order_for_pos(self):
self.ensure_one() self.ensure_one()
order_lines = [] order_lines = []
@ -109,7 +103,7 @@ class PosOrder(models.Model):
for order_line in self.lines: for order_line in self.lines:
order_line = self._prepare_done_order_line_for_pos(order_line) order_line = self._prepare_done_order_line_for_pos(order_line)
order_lines.append(order_line) order_lines.append(order_line)
for payment_line in self.statement_ids:
for payment_line in self.payment_ids:
payment_line = self._prepare_done_order_payment_for_pos( payment_line = self._prepare_done_order_payment_for_pos(
payment_line) payment_line)
payment_lines.append(payment_line) payment_lines.append(payment_line)
@ -121,14 +115,13 @@ class PosOrder(models.Model):
'partner_id': self.partner_id.id, 'partner_id': self.partner_id.id,
'fiscal_position': self.fiscal_position_id.id, 'fiscal_position': self.fiscal_position_id.id,
'line_ids': order_lines, 'line_ids': order_lines,
'statement_ids': payment_lines,
'to_invoice': bool(self.invoice_id),
'payment_lines': payment_lines,
'to_invoice': bool(self.account_move),
'returned_order_id': self.returned_order_id.id, 'returned_order_id': self.returned_order_id.id,
'returned_order_reference': self.returned_order_reference, 'returned_order_reference': self.returned_order_reference,
} }
return res return res
@api.multi
def _prepare_done_order_line_for_pos(self, order_line): def _prepare_done_order_line_for_pos(self, order_line):
self.ensure_one() self.ensure_one()
return { return {
@ -138,20 +131,17 @@ class PosOrder(models.Model):
'discount': order_line.discount, 'discount': order_line.discount,
} }
@api.multi
def _prepare_done_order_payment_for_pos(self, payment_line): def _prepare_done_order_payment_for_pos(self, payment_line):
self.ensure_one() self.ensure_one()
return { return {
'journal_id': payment_line.journal_id.id,
'payment_method_id': payment_line.payment_method_id.id,
'amount': payment_line.amount, 'amount': payment_line.amount,
} }
@api.multi
def load_done_order_for_pos(self): def load_done_order_for_pos(self):
self.ensure_one() self.ensure_one()
return self._prepare_done_order_for_pos() return self._prepare_done_order_for_pos()
@api.model
def _order_fields(self, ui_order): def _order_fields(self, ui_order):
res = super()._order_fields(ui_order) res = super()._order_fields(ui_order)
res.update({ res.update({

1
pos_order_mgmt/readme/CONTRIBUTORS.rst

@ -3,3 +3,4 @@
* Carlos Martínez <carlos@domatix.com> * Carlos Martínez <carlos@domatix.com>
* Pierrick Brun <pierrick.brun@akretion.com> * Pierrick Brun <pierrick.brun@akretion.com>
* Iván Todorovich <ivan.todorovich@druidoo.io> * Iván Todorovich <ivan.todorovich@druidoo.io>
* Ammar Officewala <https://twitter.com/AmmarOfficewala>

35
pos_order_mgmt/static/src/js/widgets.js

@ -24,7 +24,7 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
return this._super(); return this._super();
} }
var order = this.pos.reloaded_order; var order = this.pos.reloaded_order;
this.$('.pos-receipt-container').html(QWeb.render('PosTicket', {
this.$('.pos-receipt-container').html(QWeb.render('OrderReceipt', {
widget: this, widget: this,
pos: this.pos, pos: this.pos,
order: order, order: order,
@ -180,13 +180,13 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
if (this.pos.config.iface_print_via_proxy) { if (this.pos.config.iface_print_via_proxy) {
this.pos.proxy.print_receipt(QWeb.render( this.pos.proxy.print_receipt(QWeb.render(
'XmlReceipt', {
receipt: order.export_for_printing(),
'OrderReceipt', {
widget: this, widget: this,
pos: this.pos, pos: this.pos,
order: order, order: order,
receipt: order.export_for_printing(),
orderlines: order.get_orderlines(), orderlines: order.get_orderlines(),
paymentlines: order.get_paymentlines(),
paymentlinesf: order.get_paymentlines(),
})); }));
this.pos.set_order(this.pos.current_order); this.pos.set_order(this.pos.current_order);
this.pos.current_order = false; this.pos.current_order = false;
@ -199,7 +199,9 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
// If it's invoiced, we also print the invoice // If it's invoiced, we also print the invoice
if (order_data.to_invoice) { if (order_data.to_invoice) {
this.pos.chrome.do_action('point_of_sale.pos_invoice_report', { this.pos.chrome.do_action('point_of_sale.pos_invoice_report', {
additional_context: { active_ids: [order_data.id] }
additional_context: {
active_ids: [order_data.id]
}
}) })
} }
@ -279,18 +281,18 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
// Get Payment lines // Get Payment lines
if (['print'].indexOf(action) !== -1) { if (['print'].indexOf(action) !== -1) {
var paymentLines = order_data.statement_ids || [];
var paymentLines = order_data.payment_lines || [];
_.each(paymentLines, function(paymentLine) { _.each(paymentLines, function(paymentLine) {
var line = paymentLine; var line = paymentLine;
// In case of local data // In case of local data
if (line.length === 3) { if (line.length === 3) {
line = line[2]; line = line[2];
} }
_.each(self.pos.cashregisters, function (cashregister) {
if (cashregister.journal.id === line.journal_id) {
_.each(self.pos.payment_methods, function(payment_method) {
if (payment_method.id === line.payment_method_id) {
if (line.amount > 0) { if (line.amount > 0) {
// If it is not change // If it is not change
order.add_paymentline(cashregister);
order.add_paymentline(payment_method);
order.selected_paymentline.set_amount( order.selected_paymentline.set_amount(
line.amount); line.amount);
} }
@ -339,14 +341,15 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
model: 'pos.order', model: 'pos.order',
method: 'load_done_order_for_pos', method: 'load_done_order_for_pos',
args: [order_id], args: [order_id],
}).fail(function (error) {
if (parseInt(error.code, 10) === 200) {
}).guardedCatch(function(reason) {
if (parseInt(reason.message.code, 10) === 200) {
// Business Logic Error, not a connection problem // Business Logic Error, not a connection problem
self.gui.show_popup( self.gui.show_popup(
'error-traceback', { 'error-traceback', {
'title': error.data.message, 'title': error.data.message,
'body': error.data.debug, 'body': error.data.debug,
});
}
);
} else { } else {
self.gui.show_popup('error', { self.gui.show_popup('error', {
'title': _t('Connection error'), 'title': _t('Connection error'),
@ -393,8 +396,8 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
.local().format('YYYY-MM-DD HH:mm:ss'); .local().format('YYYY-MM-DD HH:mm:ss');
} }
}); });
}).fail(function (error, event) {
if (parseInt(error.code, 10) === 200) {
}).guardedCatch(function(reason) {
if (parseInt(reason.message.code, 10) === 200) {
// Business Logic Error, not a connection problem // Business Logic Error, not a connection problem
self.gui.show_popup( self.gui.show_popup(
'error-traceback', { 'error-traceback', {
@ -410,14 +413,14 @@ odoo.define('pos_order_mgmt.widgets', function (require) {
' is currently offline'), ' is currently offline'),
}); });
} }
event.preventDefault();
reason.event.preventDefault();
}); });
}, },
perform_search: function() { perform_search: function() {
var self = this; var self = this;
return this.search_done_orders(self.search_query) return this.search_done_orders(self.search_query)
.done(function () {
.then(function() {
self.render_list(); self.render_list();
}); });
}, },

14
pos_order_mgmt/tests/test_module.py

@ -30,8 +30,8 @@ class TestModule(TransactionCase):
orders_data = self.PosOrder.search_done_orders_for_pos( orders_data = self.PosOrder.search_done_orders_for_pos(
[], self.pos_config.current_session_id.id) [], self.pos_config.current_session_id.id)
self.assertEqual(len(orders_data), 1) self.assertEqual(len(orders_data), 1)
self.assertEqual(
orders_data[0]['id'], order.id)
self.assertEqual(order.id,
orders_data[0]['id'])
detail_data = order.load_done_order_for_pos() detail_data = order.load_done_order_for_pos()
self.assertEqual( self.assertEqual(
@ -58,13 +58,11 @@ class TestModule(TransactionCase):
'price_subtotal_incl': 0.9, 'price_subtotal_incl': 0.9,
}]], }]],
'statement_ids': [[0, 0, { 'statement_ids': [[0, 0, {
'journal_id': self.pos_config.journal_ids[0].id,
'payment_method_id': self.pos_config.payment_method_ids[0].id,
'amount': 0.9, 'amount': 0.9,
'name': fields.Datetime.now(), 'name': fields.Datetime.now(),
'account_id':
self.env.user.partner_id.property_account_receivable_id.id,
'statement_id':
self.pos_config.current_session_id.statement_ids[0].id,
'payment_date' : fields.Datetime.now(),
'session_id' : self.pos_config.current_session_id.id,
}]], }]],
'creation_date': u'2018-09-27 15:51:03', 'creation_date': u'2018-09-27 15:51:03',
'amount_tax': 0, 'amount_tax': 0,
@ -76,5 +74,5 @@ class TestModule(TransactionCase):
}} }}
result = self.PosOrder.create_from_ui([order_data]) result = self.PosOrder.create_from_ui([order_data])
order = self.PosOrder.browse(result[0])
order = self.PosOrder.browse(result[0].get('id'))
return order return order
Loading…
Cancel
Save