[FIX] point_of_sale: Begin the connection between the frontend and the backend
bzr revid: stw@openerp.com-20120508152805-874rbq1jv8mpvwo6
This commit is contained in:
parent
d4cbce0ce7
commit
72c89a2028
|
@ -174,11 +174,12 @@ class pos_session(osv.osv):
|
|||
|
||||
'state' : fields.selection(POS_SESSION_STATE, 'State', required=True, readonly=True, select=1),
|
||||
|
||||
'cash_register_id' : fields.many2one('account.bank.statement', 'Bank Account Statement'),
|
||||
'cash_register_id' : fields.many2one('account.bank.statement', 'Bank Account Statement', ondelete='cascade'),
|
||||
|
||||
'details_ids' : fields.related('cash_register_id', 'details_ids',
|
||||
type='one2many', relation='account.cashbox.line',
|
||||
string='CashBox Lines'),
|
||||
'journal_ids' : fields.related('config_id', 'journal_ids', type='many2many', relation='account.journal', string='Journals'),
|
||||
'order_ids' : fields.one2many('pos.order', 'session_id', 'Orders'),
|
||||
}
|
||||
|
||||
|
@ -192,7 +193,7 @@ class pos_session(osv.osv):
|
|||
('uniq_name', 'unique(name)', "The name of this POS Session must be unique !"),
|
||||
]
|
||||
|
||||
def _create_cash_register(self, cr, uid, pos_config, context=None):
|
||||
def _create_cash_register(self, cr, uid, pos_config, user_id, context=None):
|
||||
if not pos_config:
|
||||
return False
|
||||
|
||||
|
@ -209,6 +210,7 @@ class pos_session(osv.osv):
|
|||
|
||||
values = {
|
||||
'journal_id' : journal_id,
|
||||
'user_id' : pos_config.user_id and pos_config.user_id.id or uid,
|
||||
}
|
||||
cash_register_id = proxy.create(cr, uid, values, context=context)
|
||||
|
||||
|
@ -220,15 +222,31 @@ class pos_session(osv.osv):
|
|||
if config_id:
|
||||
pos_config = self.pool.get('pos.config').browse(cr, uid, config_id, context=context)
|
||||
name = pos_config.sequence_id._next()
|
||||
user_id = values.get('user_id', uid) or uid
|
||||
values.update(
|
||||
name=name,
|
||||
cash_register_id=self._create_cash_register(cr, uid, pos_config, context=context),
|
||||
cash_register_id=self._create_cash_register(cr, uid, pos_config, user_id=user_id, context=context),
|
||||
)
|
||||
else:
|
||||
raise osv.except_osv(_('Error!'), _('There is no POS Config attached to this POS Session'))
|
||||
|
||||
return super(pos_session, self).create(cr, uid, values, context=context)
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.cash_register_id:
|
||||
obj.cash_register_id.unlink(context=context)
|
||||
return True
|
||||
|
||||
def on_change_config(self, cr, uid, ids, config_id, context=None):
|
||||
result = dict(value=dict())
|
||||
if not config_id:
|
||||
result['value']['user_id'] = uid
|
||||
else:
|
||||
result['value']['user_id'] = self.pool.get('pos.config').browse(cr, uid, config_id, context=context).user_id.id
|
||||
|
||||
return result
|
||||
|
||||
def wkf_action_open(self, cr, uid, ids, context=None):
|
||||
# si pas de date start_at, je balance une date, sinon on utilise celle de l'utilisateur
|
||||
for record in self.browse(cr, uid, ids, context=context):
|
||||
|
@ -271,7 +289,7 @@ class pos_session(osv.osv):
|
|||
domain = [
|
||||
('state', '=', 'open'),
|
||||
('start_at', '>=', time.strftime('%Y-%m-%d 00:00:00')),
|
||||
('config_id.user_id', '=', uid),
|
||||
('user_id', '=', uid),
|
||||
]
|
||||
session_ids = self.search(cr, uid, domain, context=context, limit=1, order='start_at desc')
|
||||
session_id = session_ids[0] if session_ids else False
|
||||
|
@ -287,7 +305,7 @@ class pos_session(osv.osv):
|
|||
config = pos_config_proxy.browse(cr, uid, pos_config_ids[0], context=context)
|
||||
|
||||
values = {
|
||||
'state' : 'draft',
|
||||
'state' : 'new',
|
||||
'start_at' : time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'config_id' : config.id,
|
||||
'journal_id' : config.journal_id.id,
|
||||
|
@ -322,22 +340,24 @@ class pos_order(osv.osv):
|
|||
def create_from_ui(self, cr, uid, orders, context=None):
|
||||
#_logger.info("orders: %r", orders)
|
||||
list = []
|
||||
session_id = self.pool.get('pos.session').get_current_session()
|
||||
session_id = self.pool.get('pos.session').get_current_session(cr, uid, context=context)
|
||||
for order in orders:
|
||||
# order :: {'name': 'Order 1329148448062', 'amount_paid': 9.42, 'lines': [[0, 0, {'discount': 0, 'price_unit': 1.46, 'product_id': 124, 'qty': 5}], [0, 0, {'discount': 0, 'price_unit': 0.53, 'product_id': 62, 'qty': 4}]], 'statement_ids': [[0, 0, {'journal_id': 7, 'amount': 9.42, 'name': '2012-02-13 15:54:12', 'account_id': 12, 'statement_id': 21}]], 'amount_tax': 0, 'amount_return': 0, 'amount_total': 9.42}
|
||||
order['session_id'] = session_id
|
||||
order_obj = self.pool.get('pos.order')
|
||||
# get statements out of order because they will be generated with add_payment to ensure
|
||||
# the module behavior is the same when using the front-end or the back-end
|
||||
statement_ids = order.pop('statement_ids')
|
||||
if not order['data']['statement_ids']:
|
||||
continue
|
||||
statement_ids = order['data'].pop('statement_ids')
|
||||
order_id = self.create(cr, uid, order, context)
|
||||
list.append(order_id)
|
||||
# call add_payment; refer to wizard/pos_payment for data structure
|
||||
# add_payment launches the 'paid' signal to advance the workflow to the 'paid' state
|
||||
data = {
|
||||
'journal': statement_ids[0][2]['journal_id'],
|
||||
'amount': order['amount_paid'],
|
||||
'payment_name': order['name'],
|
||||
'amount': order['data']['amount_paid'],
|
||||
'payment_name': order['data']['name'],
|
||||
'payment_date': statement_ids[0][2]['name'],
|
||||
}
|
||||
order_obj.add_payment(cr, uid, order_id, data, context=context)
|
||||
|
@ -550,6 +570,8 @@ class pos_order(osv.osv):
|
|||
|
||||
def add_payment(self, cr, uid, order_id, data, context=None):
|
||||
"""Create a new payment for the order"""
|
||||
if not context:
|
||||
context = {}
|
||||
statement_obj = self.pool.get('account.bank.statement')
|
||||
statement_line_obj = self.pool.get('account.bank.statement.line')
|
||||
prod_obj = self.pool.get('product.product')
|
||||
|
|
|
@ -852,7 +852,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="PoS Session">
|
||||
<group colspan="4" col="6">
|
||||
<field name="config_id" />
|
||||
<field name="config_id" on_change="on_change_config(config_id)" />
|
||||
<field name="name" />
|
||||
<field name="user_id" />
|
||||
<field name="start_at" />
|
||||
|
@ -870,6 +870,7 @@
|
|||
<field name="subtotal_closing" string="Closing Subtotal"/>
|
||||
</tree>
|
||||
</field>
|
||||
<field name="journal_ids" colspan="4" nolabel="1" />
|
||||
</page>
|
||||
</notebook>
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ access_account_period_pos_manager,account.period pos manager,account.model_accou
|
|||
access_account_fiscalyear_pos_user,account.fiscalyear user,account.model_account_fiscalyear,group_pos_user,1,1,1,0
|
||||
access_account_fiscalyear_pos_manager,account.fiscalyear manager,account.model_account_fiscalyear,group_pos_manager,1,0,0,0
|
||||
access_account_cashbox_line,account.cashbox.line,account.model_account_cashbox_line,group_pos_user,1,1,1,0
|
||||
access_account_journal_cashbox_line,account.cashbox.journal.line,account.model_account_journal_cashbox_line,group_pos_user,1,1,1,0
|
||||
access_account_cashbox_line_manager,account.cashbox.line manager,account.model_account_cashbox_line,group_pos_manager,1,1,1,1
|
||||
access_product_product,product.product,product.model_product_product,group_pos_user,1,0,0,0
|
||||
access_product_template_pos_user,product.template pos user,product.model_product_template,group_pos_user,1,0,0,0
|
||||
|
@ -64,3 +65,5 @@ access_product_category_manager,product.category manager,product.model_product_c
|
|||
access_product_pricelist_manager,product.pricelist manager,product.model_product_pricelist,group_pos_manager,1,0,0,0
|
||||
access_product_category_pos_manager,pos.category manager,model_pos_category,group_pos_manager,1,1,1,"1"""
|
||||
access_product_category_pos_user,pos.category user,model_pos_category,group_pos_user,1,0,0,"0"""
|
||||
access_pos_session_user,pos.session user,model_pos_session,group_pos_user,1,1,1,0
|
||||
access_pos_config_user,pos.config user,model_pos_config,group_pos_user,1,1,1,0
|
|
|
@ -67,7 +67,6 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
|
|||
'user': {},
|
||||
'orders': new module.OrderCollection(),
|
||||
'products': new module.ProductCollection(),
|
||||
//'cashRegisters': [], // new module.CashRegisterCollection(this.pos.get('bank_statements')),
|
||||
'selectedOrder': undefined,
|
||||
});
|
||||
|
||||
|
@ -85,13 +84,19 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
|
|||
return self.set({'product_list': result});
|
||||
});
|
||||
|
||||
var bank_def = fetch(
|
||||
'account.bank.statement',
|
||||
['account_id', 'currency', 'journal_id', 'state', 'name'],
|
||||
[['state','=','open'], ['user_id', '=', this.session.uid]]
|
||||
).then(function(result){
|
||||
console.log('bank_statements:',result);
|
||||
return self.set({'bank_statements': result});
|
||||
var session_def = fetch(
|
||||
'pos.session',
|
||||
['id', 'journal_ids'],
|
||||
[['state', '=', 'opened'], ['user_id', '=', this.session.uid]]
|
||||
).then(function(result) {
|
||||
console.log('pos_session:', result);
|
||||
var journal_def = fetch(
|
||||
'account.journal',
|
||||
['name'],
|
||||
[['id', 'in', result[0]['journal_ids']]]).then(function(inner_result) {
|
||||
self.set({'account_journals' : inner_result});
|
||||
});
|
||||
return self;
|
||||
});
|
||||
|
||||
var tax_def = fetch('account.tax', ['amount','price_include','type'])
|
||||
|
@ -100,10 +105,10 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
|
|||
return self.set({'taxes': result});
|
||||
});
|
||||
|
||||
$.when(cat_def,prod_def,bank_def,tax_def,this.get_app_data(), this.flush())
|
||||
$.when(cat_def, prod_def, session_def, tax_def, this.get_app_data(), this.flush())
|
||||
.pipe(_.bind(this.build_tree, this))
|
||||
.pipe(function(){
|
||||
self.set({'cashRegisters': new module.CashRegisterCollection(self.get('bank_statements')) });
|
||||
self.set({'accountJournals' : new module.AccountJournalCollection(self.get('account_journals'))});
|
||||
self.ready.resolve();
|
||||
});
|
||||
|
||||
|
@ -248,11 +253,11 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
|
|||
}
|
||||
});
|
||||
|
||||
module.CashRegister = Backbone.Model.extend({
|
||||
module.AccountJournal = Backbone.Model.extend({
|
||||
});
|
||||
|
||||
module.CashRegisterCollection = Backbone.Collection.extend({
|
||||
model: module.CashRegister,
|
||||
module.AccountJournalCollection = Backbone.Collection.extend({
|
||||
model: module.AccountJournal,
|
||||
});
|
||||
|
||||
module.Product = Backbone.Model.extend({
|
||||
|
@ -380,9 +385,11 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
|
|||
Backbone.Model.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
getAmount: function(){
|
||||
return this.get('amount');
|
||||
// FIXME
|
||||
return 0.0; //this.get('amount');
|
||||
},
|
||||
exportAsJSON: function(){
|
||||
// FIXME
|
||||
return {
|
||||
name: instance.web.datetime_to_str(new Date()),
|
||||
statement_id: this.get('id'),
|
||||
|
@ -445,9 +452,9 @@ function openerp_pos_models(module, instance){ //module is instance.point_of_sal
|
|||
}, this);
|
||||
}
|
||||
},
|
||||
addPaymentLine: function(cashRegister) {
|
||||
addPaymentLine: function(accountJournal) {
|
||||
var newPaymentline;
|
||||
newPaymentline = new module.Paymentline(cashRegister);
|
||||
newPaymentline = new module.Paymentline(accountJournal);
|
||||
/* TODO: Should be 0 for cash-like accounts */
|
||||
newPaymentline.set({
|
||||
amount: this.getDueLeft()
|
||||
|
|
|
@ -74,22 +74,22 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
|
|||
performPayment: function(event) {
|
||||
if (this.pos.get('selectedOrder').get('screen') === 'receipt')
|
||||
return;
|
||||
var cashRegister, cashRegisterCollection, cashRegisterId;
|
||||
var accountJournal, accountJournalCollection, accountJournalId;
|
||||
/* set correct view */
|
||||
this.pos.screen_selector.set_current_screen('payment');
|
||||
|
||||
cashRegisterId = event.currentTarget.attributes['cash-register-id'].nodeValue;
|
||||
cashRegisterCollection = this.pos.get('cashRegisters');
|
||||
cashRegister = cashRegisterCollection.find(_.bind( function(item) {
|
||||
return (item.get('id')) === parseInt(cashRegisterId, 10);
|
||||
accountJournalId = event.currentTarget.attributes['account-journal-id'].nodeValue;
|
||||
accountRegisterCollection = this.pos.get('accountJournals');
|
||||
accountJournal = accountRegisterCollection.find(_.bind(function(item) {
|
||||
return (item.get('id')) === parseInt(accountJournalId, 10);
|
||||
}, this));
|
||||
return (this.pos.get('selectedOrder')).addPaymentLine(cashRegister);
|
||||
return (this.pos.get('selectedOrder')).addPaymentLine(accountJournal);
|
||||
},
|
||||
renderElement: function() {
|
||||
this.$element.empty();
|
||||
return (this.pos.get('cashRegisters')).each(_.bind( function(cashRegister) {
|
||||
return (this.pos.get('accountJournals')).each(_.bind(function(accountJournal) {
|
||||
var button = new module.PaymentButtonWidget();
|
||||
button.model = cashRegister;
|
||||
button.model = accountJournal;
|
||||
button.appendTo(this.$element);
|
||||
}, this));
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
|
|||
renderElement: function() {
|
||||
this.$element.html(this.template_fct({
|
||||
id: this.model.get('id'),
|
||||
name: (this.model.get('journal_id'))[1]
|
||||
name: this.model.get('name')
|
||||
}));
|
||||
return this;
|
||||
}
|
||||
|
@ -825,15 +825,6 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
|
|||
this.buildWidgets();
|
||||
|
||||
instance.webclient.set_content_full_screen(true);
|
||||
|
||||
if (self.pos.get('bank_statements').length === 0)
|
||||
return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_open_statement']], ['res_id']).pipe(
|
||||
_.bind(function(res) {
|
||||
return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) {
|
||||
var action = result.result;
|
||||
this.do_action(action);
|
||||
}, this));
|
||||
}, this));
|
||||
}, this));
|
||||
},
|
||||
render: function() {
|
||||
|
@ -1054,15 +1045,6 @@ function openerp_pos_widgets(module, instance){ //module is instance.point_of_sa
|
|||
},
|
||||
close: function() {
|
||||
this.pos.barcode_reader.disconnect();
|
||||
|
||||
return new instance.web.Model("ir.model.data").get_func("search_read")([['name', '=', 'action_pos_close_statement']], ['res_id']).pipe(
|
||||
_.bind(function(res) {
|
||||
return this.rpc('/web/action/load', {'action_id': res[0]['res_id']}).pipe(_.bind(function(result) {
|
||||
var action = result.result;
|
||||
action.context = _.extend(action.context || {}, {'cancel_action': {type: 'ir.actions.client', tag: 'default_home'}});
|
||||
this.do_action(action);
|
||||
}, this));
|
||||
}, this));
|
||||
},
|
||||
destroy: function() {
|
||||
instance.webclient.set_content_full_screen(false);
|
||||
|
|
|
@ -350,7 +350,7 @@
|
|||
</td>
|
||||
</t>
|
||||
<t t-name="pos-payment-button-template">
|
||||
<button class="payment-button" t-att-cash-register-id="id">
|
||||
<button class="payment-button" t-att-account-journal-id="id">
|
||||
<t t-esc="name"/>
|
||||
</button>
|
||||
<br />
|
||||
|
|
Loading…
Reference in New Issue