Browse Source

#8306: pos_quotation_order. Refactorizar implementación del guardado del Ticket y la eliminación de un presupuesto confirmado de la lista de presupuestos.

pull/163/head
Luis J. Salvatierra 4 years ago
parent
commit
e4e94a48f5
  1. 4
      pos_quotation_order/README.rst
  2. 2
      pos_quotation_order/__manifest__.py
  3. 48
      pos_quotation_order/models/pos_quotation.py
  4. 66
      pos_quotation_order/static/src/js/models.js

4
pos_quotation_order/README.rst

@ -41,4 +41,8 @@ Credits
Developer: Aswani pc @ cybrosys
Contributors
============
* Imanol Aranburu <iaranburu@binovo.es>
* Luis J. Salvatierra <ljsalvatierra@binovo.es>

2
pos_quotation_order/__manifest__.py

@ -19,7 +19,7 @@
#############################################################################
{
'name': "Pos Quotation Orders",
'version': '12.0.1.0.0',
'version': '12.0.1.1.0',
'summary': """Create & Process Quotation from POS""",
'description': """This module allows to create and process quotation orders from POS.""",
'author': "Cybrosys Techno Solutions",

48
pos_quotation_order/models/pos_quotation.py

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2019-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
# Copyright 2021 Binovo IT Human Project SL
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
import psycopg2
from functools import partial
from odoo import models, fields, api, tools, _
from odoo import models, fields, api, _
from odoo.exceptions import UserError
_logger = logging.getLogger(__name__)
@ -12,42 +12,14 @@ _logger = logging.getLogger(__name__)
class PosOrder(models.Model):
_inherit = 'pos.order'
quot_ref = fields.Many2one('pos.quotation', string='Quotation Ref')
quot_ref = fields.Many2one('pos.quotation', string='Quotation Ref', copy=False)
@api.model
def create_from_ui(self, orders):
# Keep only new orders
submitted_references = [o['data']['name'] for o in orders]
pos_order = self.search([('pos_reference', 'in', submitted_references)])
existing_orders = pos_order.read(['pos_reference'])
existing_references = set([o['pos_reference'] for o in existing_orders])
orders_to_save = [o for o in orders if o['data']['name'] not in existing_references]
order_ids = []
quot_ids = []
for tmp_order in orders_to_save:
to_invoice = tmp_order['to_invoice']
order = tmp_order['data']
if to_invoice:
self._match_payment_to_invoice(order)
pos_order = self._process_order(order)
if pos_order.quot_ref:
pos_order.quot_ref.write({'state': 'confirmed'})
quot_ids.append(pos_order.quot_ref.id)
order_ids.append(pos_order.id)
try:
pos_order.action_pos_order_paid()
except psycopg2.OperationalError:
# do not hide transactional errors, the order(s) won't be saved!
raise
except Exception as e:
_logger.error('Could not fully process the POS Order: %s', tools.ustr(e))
if to_invoice:
pos_order.action_pos_order_invoice()
pos_order.invoice_id.sudo().action_invoice_open()
pos_order.account_move = pos_order.invoice_id.move_id
return order_ids, quot_ids
def _process_order(self, pos_order):
order = super()._process_order(pos_order)
if order.quot_ref:
order.quot_ref.state = 'confirmed'
return order
@api.model
def _order_fields(self, ui_order):

66
pos_quotation_order/static/src/js/models.js

@ -1,3 +1,8 @@
/* Copyright (C) 2019-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
Copyright 2021 Binovo IT Human Project SL
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
*/
odoo.define('pos_quotation_order.models', function (require) {
"use strict";
@ -43,68 +48,15 @@ models.load_models({
var posmodel_super = models.PosModel.prototype;
models.PosModel = models.PosModel.extend({
_save_to_server: function (orders, options) {
if (!orders || !orders.length) {
var result = $.Deferred();
result.resolve([]);
return result;
}
options = options || {};
var self = this;
var fields = _.find(this.models,function(model){ return model.model === 'pos.quotation'; }).fields;
var timeout = typeof options.timeout === 'number' ? options.timeout : 7500 * orders.length;
var order_ids_to_sync = _.pluck(orders, 'id');
var args = [_.map(orders, function (order) {
order.to_invoice = options.to_invoice || false;
return order;
})];
return rpc.query({
model: 'pos.order',
method: 'create_from_ui',
args: args,
kwargs: {context: session.user_context},
}, {
timeout: timeout,
shadow: !options.to_invoice
})
.then(function (server_ids) {
console.log(server_ids)
if (server_ids[1].length != 0){
console.log("dddddddddddddd")
for (var item in server_ids[1]){
rpc.query({
model: 'pos.quotation',
method: 'search_read',
args: [[['id', '=', server_ids[1][item]]], fields],
limit: 1,
}).then(function (quotation){
console.log(quotation)
var index = self.quotations.indexOf(quotation[0]);
console.log(index)
return posmodel_super._save_to_server.apply(this, arguments).then(function (server_ids) {
_.each(orders, function (o) {
if (o.data.quotation_ref) {
var index = self.quotations.indexOf(o.data.quotation_ref);
self.quotations.splice(index, 1);
});
}
}
_.each(order_ids_to_sync, function (order_id) {
self.db.remove_order(order_id);
});
self.set('failed',false);
return server_ids[0];
}).fail(function (type, error){
if(error.code === 200 ){
if (error.data.exception_type == 'warning') {
delete error.data.debug;
}
if ((!self.get('failed') || options.show_error) && !options.to_invoice) {
self.gui.show_popup('error-traceback',{
'title': error.data.message,
'body': error.data.debug
});
}
self.set('failed',error);
}
console.error('Failed to send orders:', orders);
});
}
});
});
Loading…
Cancel
Save