Odoo Help

0

How to resolve OpenERP 7 POS ir_sequence increment by 2?

By
Mark Interversus
on 1/16/16, 5:50 AM 831 views

I have a problem with my OpenERP v7 POS module. I print my POS sales on A4 format with pos.order name field on it (Order Ref, not the Receipt Ref (pos_reference)), for that I have this modification on /point_of_sale/static/src/img/js/screens.js (not my code, I think the creator was Akshay)

(...)
validateCurrentOrder: function() {
var currentOrder = this.pos.get('selectedOrder');
// Akshay; for print Order ref

try{
var res = instance.web.Model("ir.sequence").get_func("get")('pos.order').then(function(result){
//alert("selectedOrder : "+ currentOrder.get('name'));
currentOrder.get({'pos_reference':result});
$('#print_order_number').html(result);
$('#print_order_number_A4').html(result);
return result
})
}

catch(err)

{}
// End Akshay

(...)

And other pos module with pos.js like this:

openerp.pos_powerline = function (instance) {

var _t = instance.web._t;

var QWeb = instance.web.qweb;

instance.point_of_sale.PosModel = instance.point_of_sale.PosModel.extend({

load_server_data: function(){

var self = this;

var loaded = self.fetch('res.users',['name','company_id'],[['id','=',this.session.uid]])

.then(function(users){

self.set('user',users[0]);

return self.fetch('res.company',

[

'currency_id',

'email',

'website',

'company_registry',

'vat',

'name',

'phone',

'partner_id',

'logo',

'can_pos_receipt_in_A4',

],

[['id','=',users[0].company_id[0]]]);

}).then(function(companies){

self.set('company',companies[0]);

return self.fetch('res.partner',['contact_address'],[['id','=',companies[0].partner_id[0]]]);

}).then(function(company_partners){

self.get('company').contact_address = company_partners[0].contact_address;

return self.fetch('product.uom', null, null);

}).then(function(units){

self.set('units',units);

var units_by_id = {};

for(var i = 0, len = units.length; i < len; i++){

units_by_id[units[i].id] = units[i];

}

self.set('units_by_id',units_by_id);

return self.fetch('product.packaging', null, null);

}).then(function(packagings){

self.set('product.packaging',packagings);

return self.fetch('res.users', ['name','ean13'], [['ean13', '!=', false]]);

}).then(function(users){

self.set('user_list',users);

return self.fetch('res.partner', ['name','ean13','customer_id_ept'], [['ean13', '!=', false]]);

}).then(function(partners){

self.set('partner_list',partners);

return self.fetch('account.tax', ['amount', 'price_include', 'type']);

}).then(function(taxes){

self.set('taxes', taxes);

return self.fetch(

'pos.session',

['id', 'journal_ids','name','user_id','config_id','start_at','stop_at'],

[['state', '=', 'opened'], ['user_id', '=', self.session.uid]]

);

}).then(function(sessions){

self.set('pos_session', sessions[0]);

return self.fetch(

'pos.config',

['name','journal_ids','shop_id','journal_id',

'iface_self_checkout', 'iface_led', 'iface_cashdrawer',

'iface_payment_terminal', 'iface_electronic_scale', 'iface_barscan', 'iface_vkeyboard',

'iface_print_via_proxy','iface_cashdrawer','state','sequence_id','session_ids'],

[['id','=', self.get('pos_session').config_id[0]]]

);

}).then(function(configs){

var pos_config = configs[0];

self.set('pos_config', pos_config);

self.iface_electronic_scale = !!pos_config.iface_electronic_scale;

self.iface_print_via_proxy = !!pos_config.iface_print_via_proxy;

self.iface_vkeyboard = !!pos_config.iface_vkeyboard;

self.iface_self_checkout = !!pos_config.iface_self_checkout;

self.iface_cashdrawer = !!pos_config.iface_cashdrawer;

return self.fetch('sale.shop',[],[['id','=',pos_config.shop_id[0]]]);

}).then(function(shops){

self.set('shop',shops[0]);

return self.fetch('product.pricelist',['currency_id'],[['id','=',self.get('shop').pricelist_id[0]]]);

}).then(function(pricelists){

self.set('pricelist',pricelists[0]);

return self.fetch('res.currency',['symbol','position','rounding','accuracy'],[['id','=',self.get('pricelist').currency_id[0]]]);

}).then(function(currencies){

self.set('currency',currencies[0]);

return self.fetch('product.packaging',['ean','product_id']);

}).then(function(packagings){

self.db.add_packagings(packagings);

return self.fetch('pos.category', ['id','name','parent_id','child_id','image'])

}).then(function(categories){

self.db.add_categories(categories);

return self.fetch(

'product.product',

['name', 'list_price','price','pos_categ_id', 'taxes_id', 'ean13', 'default_code', 'variants',

'to_weight', 'uom_id', 'uos_id', 'uos_coeff', 'mes_type', 'description_sale', 'description', 'qty_available'],

[['sale_ok','=',true],['available_in_pos','=',true]],

{pricelist: self.get('shop').pricelist_id[0]} // context for price

);

}).then(function(products){

self.db.add_products(products);

return self.fetch(

'account.bank.statement',

['account_id','currency','journal_id','state','name','user_id','pos_session_id'],

[['state','=','open'],['pos_session_id', '=', self.get('pos_session').id]]

);

}).then(function(bank_statements){

var journals = new Array();

_.each(bank_statements,function(statement) {

journals.push(statement.journal_id[0])

});

self.set('bank_statements', bank_statements);

return self.fetch('account.journal', undefined, [['id','in', journals]]);

}).then(function(journals){

self.set('journals',journals);

// associate the bank statements with their journals.

var bank_statements = self.get('bank_statements');

for(var i = 0, ilen = bank_statements.length; i < ilen; i++){

for(var j = 0, jlen = journals.length; j < jlen; j++){

if(bank_statements[i].journal_id[0] === journals[j].id){

bank_statements[i].journal = journals[j];

bank_statements[i].self_checkout_payment_method = journals[j].self_checkout_payment_method;

}

}

}

self.set({'cashRegisters' : new instance.point_of_sale.CashRegisterCollection(self.get('bank_statements'))});

});

return loaded;

},

});

instance.point_of_sale.ReceiptScreenWidget = instance.point_of_sale.ReceiptScreenWidget.extend({

show: function(){

this._super();

var self = this;

$('ul.pos-actionbar-button-list').children("li").hide();

this.add_action_button({

label: _t('Print & Next Order'),

icon: '/point_of_sale/static/src/img/icons/png48/printer.png',

click: function(){ self.print(true); self.finishOrder();},

});

},

print: function(flag) {

if (flag) {

window.print();

}

},

});

instance.point_of_sale.ProductScreenWidget = instance.point_of_sale.ProductScreenWidget.extend({

init: function() {

this._super.apply(this, arguments);

},

start:function(){

this._super.apply(this, arguments);

orderView = new instance.point_of_sale.OrderWidget(this, {});

pos = this.pos;

selectedOrder = this.pos.get('selectedOrder');

if ($('button.select-order').length == 1) {

pos = this.pos;

$("#customer_link").click(function() {

selectedOrder = pos.get('selectedOrder');

var self = this;

new instance.web.Model("res.partner").get_func("search_read")(domain=[['customer', '=', true]], fields=['id'], offset=0, limit=20).pipe(

function(result) {

initial_ids = _.map(result, function(x) {return x['id']});

var pop = new instance.web.form.SelectCreatePopup(this);

pop.select_element(

'res.partner',

{

title: 'Selecionar Cliente',

initial_ids: initial_ids,

initial_view: 'search',

disable_multiple_selection: true

}

);

pop.on("elements_selected", self, function(element_ids) {

var dataset = new instance.web.DataSetStatic(self, 'res.partner', {});

dataset.name_get(element_ids).done(function(data) {

selectedOrder.set_client(data[0][1]);

selectedOrder.set_client_id(data[0][0]);

if (data[0][0]) {

new instance.web.Model("res.partner").get_func("read")(parseInt(data[0][0]), ['discount']).pipe(

function(result) {

if (result && result.discount) {

selectedOrder.set_client_disc(result.discount);

}

}

);

}

});

});

});

});

}

},

close: function(){

this._super();

this.pos_widget.order_widget.set_numpad_state(null);

this.pos_widget.payment_screen.set_numpad_state(null);

}

});

instance.point_of_sale.Order = instance.point_of_sale.Order.extend({

initialize: function(attributes){

Backbone.Model.prototype.initialize.apply(this, arguments);

this.set({

creationDate: new Date(),

orderLines: new instance.point_of_sale.OrderlineCollection(),

paymentLines: new instance.point_of_sale.PaymentlineCollection(),

name: "Ordem " + this.generateUniqueId(),

client: null,

client_id: null,

client_disc: 0

});

this.pos = attributes.pos;

this.selected_orderline = undefined;

this.screen_data = {}; // see ScreenSelector

this.receipt_type = 'receipt'; // 'receipt' || 'invoice'

return this;

},

getName: function() {

// PoS number in offline mode

return this.get('name');

},

set_client_id: function(client_id) {

this.set('client_id', client_id)

},

get_client_id: function(){

return this.get('client_id');

},

get_client_name: function(){

var client = this.get('client');

return client ? client : "";

},

set_client_disc: function(client_disc) {

this.set('client_disc', client_disc);

},

get_client_disc: function() {

return this.get('client_disc');

},

exportAsJSON: function() {

var orderLines, paymentLines;

orderLines = [];

(this.get('orderLines')).each(_.bind( function(item) {

return orderLines.push([0, 0, item.export_as_JSON()]);

}, this));

paymentLines = [];

(this.get('paymentLines')).each(_.bind( function(item) {

return paymentLines.push([0, 0, item.export_as_JSON()]);

}, this));

return {

name: this.getName(),

amount_paid: this.getPaidTotal(),

amount_total: this.getTotalTaxIncluded(),

amount_tax: this.getTax(),

amount_return: this.getChange(),

lines: orderLines,

statement_ids: paymentLines,

pos_session_id: this.pos.get('pos_session').id,

partner_id: parseInt(this.get_client_id()) || "",

user_id: this.pos.get('cashier') ? this.pos.get('cashier').id : this.pos.get('user').id,

};

},

addProduct: function(product, options){

options = options || {};

var attr = product.toJSON();

attr.pos = this.pos;

attr.order = this;

var line = new instance.point_of_sale.Orderline({}, {pos: this.pos, order: this, product: product});

var partner_id = parseInt(this.get_client_id());

var discount = parseInt(this.get_client_disc());

if(options.quantity !== undefined){

line.set_quantity(options.quantity);

}

if(options.price !== undefined){

line.set_unit_price(options.price);

}

if(partner_id && discount) {

line.set_discount(discount);

}

var last_orderline = this.getLastOrderline();

if( last_orderline && last_orderline.can_be_merged_with(line) && options.merge !== false){

last_orderline.merge(line);

}else{

this.get('orderLines').add(line);

}

this.selectLine(this.getLastOrderline());

},

});

}


And pos.xml where it calls the print_order_number_A4

<?xml version="1.0" encoding="UTF-8"?>

<templates id="template" xml:space="preserve">

<t t-extend="ProductScreenWidget">

<t t-jquery="tr.header-row" t-operation="before">

<tr class="selection-area">

<td style="padding-top: 7px;">

<span class='button_select' id="customer_link">

Selecionar Cliente

</span>

</td>

</tr>

</t>

</t>

<t t-extend="OrderButtonWidget">

<t t-jquery="li.order-selector-button" t-operation="replace">

<li class="order-selector-button">

<button class="select-order"><t t-esc="(widget.order.get_client() ? widget.order.get_client()+' : ':'') + widget.order.get('creationDate').toString('t')"/></button>

</li>

</t>

</t>

<t t-name="ProductWidget">

<li class='product'>

<a href="#">

<div class="product-img">

<img src='' /> <!-- the product thumbnail -->

<t t-if="!widget.model.get('to_weight')">

<span class="price-tag">

<t t-esc="widget.format_currency(widget.model.get('price'))"/>

</span>

</t>

<t t-if="widget.model.get('to_weight')">

<span class="price-tag">

<t t-esc="widget.format_currency(widget.model.get('price'))+'/Kg'"/>

</span>

</t>

</div>

<div class="product-name">

<t t-esc="widget.model.get('name')"/>

</div>

<div class="product-qty">

<t t-if="widget.model.get('qty_available') &lt;= 0">

<div class="product-qty-neg">

<t t-esc="widget.model.get('qty_available')"/>

</div>

</t>

<t t-if="widget.model.get('qty_available') > 0">

<t t-esc="widget.model.get('qty_available')"/>

</t>

</div>

</a>

</li>

</t>

<!-- <t t-extend="PosTicket"> -->

<!-- <t t-jquery="div.pos-sale-ticket t:nth-child(7)" t-operation="after"><br /> -->

<!-- Customer Name: <t t-esc="widget.currentOrder.get_client_name()"/> -->

<!-- </t> -->

<!-- </t> -->

<t t-extend="PosTicket">

<t t-jquery="div.pos-sale-ticket" t-operation="replace">

<t t-if="widget.company.can_pos_receipt_in_A4 == false">

<div class="pos-sale-ticket">

<div class="pos-right-align"><t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate + ' ' +

Date.CultureInfo.formatPatterns.longTime)"/> <t t-esc="widget.currentOrder.attributes.name"/></div>

<br />

<t t-esc="widget.company.name"/><br />

Phone: <t t-esc="widget.company.phone || ''"/><br />

User: <t t-esc="widget.user.name"/><br />

Cliente: <t t-esc="widget.currentOrder.get_client_name()"/><br />

No.: <t t-esc="widget.currentOrder.get_client_id()"/><br />

Loja: <t t-esc="widget.shop_obj.name"/><br />

<br />

<table>

<colgroup>

<col width='50%' />

<col width='25%' />

<col width='25%' />

</colgroup>

<tr t-foreach="widget.currentOrderLines.toArray()" t-as="orderline">

<td>

<t t-esc="orderline.get_product().get('name')"/>

<t t-if="orderline.get_discount() > 0">

<div class="pos-disc-font">

With a <t t-esc="orderline.get_discount()"/>% discount

</div>

</t>

</td>

<td class="pos-right-align">

<t t-esc="orderline.get_quantity_str_with_unit()"/>

</td>

<td class="pos-right-align">

<t t-esc="widget.format_currency(orderline.get_product().get('price'))"/>

</td>

</tr>

</table>

<br />

<table>

<tr><td>Subtotal:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getSubtotal())"/>

</td></tr>

<tr><td>Tax:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getTax())"/>

</td></tr>

<tr><td>Discount:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getDiscountTotal())"/>

</td></tr>

<tr class="emph"><td>Total:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getTotalTaxIncluded())"/>

</td></tr>

</table>

<br />

<table>

<tr t-foreach="widget.currentPaymentLines.toArray()" t-as="pline">

<td>

<t t-esc="pline.get_cashregister().get('journal_id')[1]"/>

</td>

<td class="pos-right-align">

<t t-esc="widget.format_currency(pline.get_amount())"/>

</td>

</tr>

</table>

<br />

<table>

<tr><td>Change:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getPaidTotal() - widget.currentOrder.getTotalTaxIncluded())"/>

</td></tr>

</table>

</div>

</t>

<!--Print Receipt for A4 -->

<t t-if="widget.company.can_pos_receipt_in_A4">

<div class="pos-sale-ticket_A4" style=" width: 680px;">

<div class="er_container">

<div style="align:left;width=40%;" id="company_logo"><img t-att-src="'data:image/png;base64,'+ widget.company.logo" width="40%"/></div>

<br />

<div class="er_address">

<div style="float:left;width:45%;">

<t t-esc="widget.company.name" /><br />

<!--Shop: <t t-esc="widget.shop_obj.name"/> <br />-->

<t t-if="widget.company.street">

<t t-esc="widget.company.street || ''"/> <br />

</t>

<t t-if="widget.company.city">

<t t-esc="widget.company.city || '' "/> <br />

</t>

NIF : <t t-esc="widget.company.company_registry || ''"/><br />

<t t-if="widget.company.phone">

<t t-esc="widget.company.phone || ''"/> <br />

</t>

<t t-if="widget.company.email">

<t t-esc="widget.company.email || ''"/>

</t>

</div>

<div style="text-align:left; float:right;width:40%;margin-right: 12px;">

<t t-esc="widget.currentOrder.get_client_name()" /><br />

<!--<t t-esc="widget.currentOrder.get_client_vat()" />-->

</div>

<div style="clear: both;" />

<br /><br />

<div class="er_v_dinheiro">

<b> <span id="print_order_number_A4"></span> </b> <br />

<!--Ref No: <b> <t t-esc="widget.currentOrder.getName()" /></b>-->

</div>

<div style="clear: both;" />

<br />

<div style="clear: both;" />

<div class="er_data_table" style="width: 101%;">

<div class="er_data_tr">

<div class="er_data_th">Operador</div>

<div class="er_data_th">Data da Fatura</div>

<div class="er_data_th">Cod. Cliente</div>

</div>

<div class="er_data_tr">

<div class="er_data_td"><t t-esc="widget.user.name"/></div>

<div class="er_data_td"><t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate + ' ' +

Date.CultureInfo.formatPatterns.shortTime)"/></div>

<div class="er_data_td">

n.º

<t t-if="widget.currentOrder.get_client_id()">

<t t-if="widget.currentOrder.get_client_id()"> <t t-esc="widget.currentOrder.get_client_id()"/> </t>

<t t-if="widget.currentOrder.get_client_id() == false"> - </t>

</t>

</div>

</div>

</div>

</div>

<!--<div style="text-align:left; float:right;width:40%;margin-right: 12px;">

Customer Name: <t t-esc="widget.currentOrder.get_client_name()"/>

</div>-->

<div style="clear: both;">

<br />

</div>

<div class="er_order_line_table">

<div class="er_order_line_tr">

<div class="er_order_line_discription_th" style="width:47%;">Descrição</div>

<div style="width:6%;" class="er_order_line_th_qty">Quant.</div>

<div class="er_order_line_th" align="center" style="width:21%;">Preço Un.</div>

<div class="er_order_line_th_qty" align="center" style="width:13%;">Desc.(%)</div>

<div class="er_order_line_th" align="right" style="width:13%;">Preço</div>

</div>

<div style="clear: both;" />

<hr />

<table width="100%" >

<tr class="er_order_line_tr" t-foreach="widget.currentOrderLines.toArray()" t-as="orderline">

<td class="er_order_line_discription_td" style="width:47%;">

<t t-if="orderline.get_product().get('default_code')">

<t t-esc="orderline.get_product().get('default_code')"/>

-

</t>

<t t-esc="orderline.get_product().get('name')"/>

</td>

<td class="er_order_line_td_qty" align="center" style="width:6%;">

<t t-esc="orderline.get_quantity_str_with_unit()"/>

</td>

<td class="er_order_line_td" align="center" style="width:21%;">

<t t-esc="widget.format_currency(orderline.get_product().get('price'))"/>

</td>

<td class="er_order_line_td_qty" align="center" style="width:13%;">

<t t-if="orderline">

<t t-if="orderline.get_discount() == false">-</t>

<t t-if="orderline.get_discount() > 0"> <t t-esc="orderline.get_discount()"/>%</t>

</t>

</td>

<td class="er_order_line_td" align="right" style="width:13%;">

<t t-esc="widget.format_currency(orderline.get_product().get('price') * (1 - orderline.get_discount()/100) * orderline.get_quantity())"/>

</td>

</tr>

</table>

</div>

<div style="clear: both;" />

<!--<br />

<table class="er_table">

<tr class="er_order_line_tr">

<th class="er_order_line_discription_th">Product Description</th>

<th class="pos-right-align" >Quantity</th>

<th class="pos-right-align">Price </th>

</tr>

<tr t-foreach="widget.currentOrderLines.toArray()" t-as="orderline">

<td>

<t t-esc="orderline.get_product().get('name')"/>

<t t-if="orderline.get_discount() > 0">

<div class="pos-disc-font">

With a <t t-esc="orderline.get_discount()"/>% discount

</div>

</t>

</td>

<td class="pos-right-align">

<t t-esc="orderline.get_quantity_str_with_unit()"/>

</td>

<td class="pos-right-align">

<t t-esc="widget.format_currency(orderline.get_display_price())"/>

</td>

</tr>

</table>-->

<br />

<hr width="38%" align="right"/>

<div style="clear: both;" />

<table class="er_total_container">

<!--<tr><td>Subtotal:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getSubtotal())"/>

</td></tr>

<tr><td>Tax:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getTax())"/>

</td></tr>-->

<tr><td>Discount:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getDiscountTotal())"/>

</td></tr>

<tr><td>Change:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getPaidTotal() - widget.currentOrder.getTotalTaxIncluded())"/>

</td></tr>

<tr class="emph"><td>Total:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getTotalTaxIncluded())"/>

</td></tr>

</table>

<div style="clear: both;" />

<br /><br /><br />

<hr />

<div style="clear: both;" />

<table class="er_table">

<tr t-foreach="widget.currentPaymentLines.toArray()" t-as="pline">

<td>

<t t-esc="pline.get_cashregister().get('journal_id')[1]"/>

</td>

<td class="pos-right-align">

<t t-esc="widget.format_currency(pline.get_amount())"/>

</td>

</tr>

</table>

<br />

<!--<table width="100%">

<tr><td>Change:</td><td class="pos-right-align">

<t t-esc="widget.format_currency(widget.currentOrder.getPaidTotal() - widget.currentOrder.getTotalTaxIncluded())"/>

</td></tr>

<div style="clear: both;" />

</table>-->

<div style="clear: both;" />

<br /><br /><br /><br /><br />

<div style="clear: both;" />

<hr />

<div style="clear: both;" />

<div class="er_footer">

<t t-if="widget.company.phone">

<t t-esc="widget.company.phone"/> -

</t>

<t t-if="widget.company.website">

<t t-esc="widget.company.website"/> -

</t>

<t t-if="widget.company.company_registry"> NIF:

<t t-esc="widget.company.company_registry"/>

</t> 

</div>

</div>

</div>

</t>

</t>

</t>

</templates>

So I know that the problem is that ir.sequence are called two times (one on screen.js, the other on def create, line 673 of point_of_sale.py) so it create two numbers for one sale (one is printed on the front end POS, the other goes stored on database and shows on pos orders list). What should I do to fix it and still get the Order Ref on A4 POS print receipt?

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/16/16, 5:50 AM
Seen: 831 times
Last updated: 1/16/16, 6:25 AM