From f30d1585e52237f042305889a12ad889e2f2bb37 Mon Sep 17 00:00:00 2001 From: "Sanjay Gohel (Open ERP)" Date: Thu, 18 Oct 2012 18:25:06 +0530 Subject: [PATCH 1/4] [IMP]set pos company in statment create bzr revid: sgo@tinyerp.com-20121018125506-lrdsyklk0oap2u5z --- addons/account/account_bank_statement.py | 2 +- addons/point_of_sale/point_of_sale.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 549363ce269..401fac4e279 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -61,7 +61,7 @@ class account_bank_statement(osv.osv): return res def _get_period(self, cr, uid, context=None): - periods = self.pool.get('account.period').find(cr, uid) + periods = self.pool.get('account.period').find(cr, uid,context=context) if periods: return periods[0] return False diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index 85eb1dd9612..e0b33d6df84 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -296,6 +296,8 @@ class pos_session(osv.osv): ] def create(self, cr, uid, values, context=None): + if context is None: + context = {} config_id = values.get('config_id', False) or False if config_id: # journal_id is not required on the pos_config because it does not @@ -304,6 +306,7 @@ class pos_session(osv.osv): # the .xml files as the CoA is not yet installed. jobj = self.pool.get('pos.config') pos_config = jobj.browse(cr, uid, config_id, context=context) + context.update({'company_id': pos_config.shop_id.company_id.id}) if not pos_config.journal_id: jid = jobj.default_get(cr, uid, ['journal_id'], context=context)['journal_id'] if jid: @@ -330,6 +333,7 @@ class pos_session(osv.osv): bank_values = { 'journal_id' : journal.id, 'user_id' : uid, + 'company_id' : pos_config.shop_id.company_id.id } statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context) bank_statement_ids.append(statement_id) From ce874db95a7e6feb848833450aad7c1ab858f6f5 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sat, 3 Nov 2012 16:25:04 +0100 Subject: [PATCH 2/4] [FIX] POS bzr revid: fp@openerp.com-20121103152504-f3o6ce0e833hdibj --- addons/point_of_sale/point_of_sale.py | 40 +++++++++++----------- addons/point_of_sale/wizard/pos_payment.py | 2 -- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index e4d0512540b..9a4711e5f6b 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -493,17 +493,26 @@ class pos_order(osv.osv): self.add_payment(cr, uid, order_id, { 'amount': payment['amount'] or 0.0, 'payment_date': payment['name'], + 'statement_id': payment['statement_id'], 'payment_name': payment.get('note', False), 'journal': payment['journal_id'] }, context=context) if order['amount_return']: session = self.pool.get('pos.session').browse(cr, uid, order['pos_session_id'], context=context) + cash_journal = session.cash_journal_id + cash_statement = False + if not cash_journal: + cash_journal_ids = filter(lambda st: st.journal_id.type=='cash', session.statement_ids) + if not len(cash_journal_ids): + raise osv.except_osv( _('error!'), + _("No cash statement found for this session. Unable to record returned cash.")) + cash_journal = cash_journal_ids[0].journal_id self.add_payment(cr, uid, order_id, { 'amount': -order['amount_return'], 'payment_date': time.strftime('%Y-%m-%d %H:%M:%S'), 'payment_name': _('return'), - 'journal': session.cash_journal_id.id + 'journal': cash_journal.id, }, context=context) order_ids.append(order_id) wf_service = netsvc.LocalService("workflow") @@ -703,21 +712,15 @@ class pos_order(osv.osv): """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') property_obj = self.pool.get('ir.property') - curr_c = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id - curr_company = curr_c.id order = self.browse(cr, uid, order_id, context=context) args = { 'amount': data['amount'], + 'date': data.get('payment_date', time.strftime('%Y-%m-%d')), + 'name': order.name + ': ' + (data.get('payment_name', '') or ''), } - if 'payment_date' in data: - args['date'] = data['payment_date'] - args['name'] = order.name - if data.get('payment_name', False): - args['name'] = args['name'] + ': ' + data['payment_name'] + account_def = property_obj.get(cr, uid, 'property_account_receivable', 'res.partner', context=context) args['account_id'] = (order.partner_id and order.partner_id.property_account_receivable \ and order.partner_id.property_account_receivable.id) or (account_def and account_def.id) or False @@ -732,14 +735,15 @@ class pos_order(osv.osv): context.pop('pos_session_id', False) - try: - journal_id = long(data['journal']) - except Exception: - journal_id = False + journal_id = data.get('journal', False) + statement_id = data.get('statement_id', False) + assert journal_id or statement_id, "No statement_id or journal_id passed to the method!" - statement_id = False for statement in order.session_id.statement_ids: - if statement.journal_id.id == journal_id: + if statement.id == statement_id: + journal_id = statement.journal_id.id + break + elif statement.journal_id.id == journal_id: statement_id = statement.id break @@ -756,10 +760,6 @@ class pos_order(osv.osv): statement_line_obj.create(cr, uid, args, context=context) - wf_service = netsvc.LocalService("workflow") - wf_service.trg_validate(uid, 'pos.order', order_id, 'paid', cr) - wf_service.trg_write(uid, 'pos.order', order_id, cr) - return statement_id def refund(self, cr, uid, ids, context=None): diff --git a/addons/point_of_sale/wizard/pos_payment.py b/addons/point_of_sale/wizard/pos_payment.py index ca9331012b7..9511aed6331 100644 --- a/addons/point_of_sale/wizard/pos_payment.py +++ b/addons/point_of_sale/wizard/pos_payment.py @@ -43,8 +43,6 @@ class account_journal(osv.osv): return super(account_journal, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=count) -account_journal() - class pos_make_payment(osv.osv_memory): _name = 'pos.make.payment' _description = 'Point of Sale Payment' From 74476c8e22be456bd404eff611e63fa4c2d35438 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sat, 3 Nov 2012 18:12:25 +0100 Subject: [PATCH 3/4] [FIX] POS close session without cash register bzr revid: fp@openerp.com-20121103171225-nlp53s0aenamdhcg --- addons/account/account_cash_statement.py | 2 +- addons/point_of_sale/point_of_sale.py | 80 ++++++++++--------- .../point_of_sale/point_of_sale_workflow.xml | 10 ++- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index 17fa05d5f24..9a5eb93286f 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -78,7 +78,7 @@ class account_cash_statement(osv.osv): """ res = {} for statement in self.browse(cr, uid, ids, context=context): - if statement.journal_id.type not in ('cash',): + if (statement.journal_id.type not in ('cash',)) or (not statement.journal_id.cash_control): continue start = end = 0 for line in statement.details_ids: diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index 9a4711e5f6b..39c98c9faa7 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -296,49 +296,53 @@ class pos_session(osv.osv): ] def create(self, cr, uid, values, context=None): - config_id = values.get('config_id', False) or False - if config_id: - # journal_id is not required on the pos_config because it does not - # exists at the installation. If nothing is configured at the - # installation we do the minimal configuration. Impossible to do in - # the .xml files as the CoA is not yet installed. - jobj = self.pool.get('pos.config') - pos_config = jobj.browse(cr, uid, config_id, context=context) - if not pos_config.journal_id: - jid = jobj.default_get(cr, uid, ['journal_id'], context=context)['journal_id'] - if jid: - jobj.write(cr, uid, [pos_config.id], {'journal_id': jid}, context=context) - else: - raise osv.except_osv( _('error!'), - _("Unable to open the session. You have to assign a sale journal to your point of sale.")) + context = context or {} + config_id = values.get('config_id', False) or context.get('default_config_id', False) + if not config_id: + raise osv.except_osv( _('Error!'), + _("You should assign a Point of Sale to your session.")) - # define some cash journal if no payment method exists - if not pos_config.journal_ids: - journal_proxy = self.pool.get('account.journal') - cashids = journal_proxy.search(cr, uid, [('journal_user', '=', True), ('type','=','cash')], context=context) + # journal_id is not required on the pos_config because it does not + # exists at the installation. If nothing is configured at the + # installation we do the minimal configuration. Impossible to do in + # the .xml files as the CoA is not yet installed. + jobj = self.pool.get('pos.config') + pos_config = jobj.browse(cr, uid, config_id, context=context) + if not pos_config.journal_id: + jid = jobj.default_get(cr, uid, ['journal_id'], context=context)['journal_id'] + if jid: + jobj.write(cr, uid, [pos_config.id], {'journal_id': jid}, context=context) + else: + raise osv.except_osv( _('error!'), + _("Unable to open the session. You have to assign a sale journal to your point of sale.")) + + # define some cash journal if no payment method exists + if not pos_config.journal_ids: + journal_proxy = self.pool.get('account.journal') + cashids = journal_proxy.search(cr, uid, [('journal_user', '=', True), ('type','=','cash')], context=context) + if not cashids: + cashids = journal_proxy.search(cr, uid, [('type', '=', 'cash')], context=context) if not cashids: - cashids = journal_proxy.search(cr, uid, [('type', '=', 'cash')], context=context) - if not cashids: - cashids = journal_proxy.search(cr, uid, [('journal_user','=',True)], context=context) + cashids = journal_proxy.search(cr, uid, [('journal_user','=',True)], context=context) - jobj.write(cr, uid, [pos_config.id], {'journal_ids': [(6,0, cashids)]}) + jobj.write(cr, uid, [pos_config.id], {'journal_ids': [(6,0, cashids)]}) - pos_config = jobj.browse(cr, uid, config_id, context=context) - bank_statement_ids = [] - for journal in pos_config.journal_ids: - bank_values = { - 'journal_id' : journal.id, - 'user_id' : uid, - } - statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context) - bank_statement_ids.append(statement_id) + pos_config = jobj.browse(cr, uid, config_id, context=context) + bank_statement_ids = [] + for journal in pos_config.journal_ids: + bank_values = { + 'journal_id' : journal.id, + 'user_id' : uid, + } + statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context) + bank_statement_ids.append(statement_id) - values.update({ - 'name' : pos_config.sequence_id._next(), - 'statement_ids' : [(6, 0, bank_statement_ids)], - 'config_id': config_id - }) + values.update({ + 'name' : pos_config.sequence_id._next(), + 'statement_ids' : [(6, 0, bank_statement_ids)], + 'config_id': config_id + }) return super(pos_session, self).create(cr, uid, values, context=context) @@ -390,7 +394,7 @@ class pos_session(osv.osv): def wkf_action_closing_control(self, cr, uid, ids, context=None): for session in self.browse(cr, uid, ids, context=context): for statement in session.statement_ids: - if statement != session.cash_register_id and statement.balance_end != statement.balance_end_real: + if (statement != session.cash_register_id) and (statement.balance_end != statement.balance_end_real): self.pool.get('account.bank.statement').write(cr, uid, [statement.id], {'balance_end_real': statement.balance_end}) return self.write(cr, uid, ids, {'state' : 'closing_control', 'stop_at' : time.strftime('%Y-%m-%d %H:%M:%S')}, context=context) diff --git a/addons/point_of_sale/point_of_sale_workflow.xml b/addons/point_of_sale/point_of_sale_workflow.xml index 601fbae4d23..ad7b149f6bc 100644 --- a/addons/point_of_sale/point_of_sale_workflow.xml +++ b/addons/point_of_sale/point_of_sale_workflow.xml @@ -152,7 +152,7 @@ - + close cash_control == False @@ -163,5 +163,13 @@ close + + + + cash_control == False + + + + From 4a15e55895c9165043fb527ed186f4fa90cdc8b0 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Sat, 3 Nov 2012 18:16:27 +0100 Subject: [PATCH 4/4] [FIX] bug pos bzr revid: fp@openerp.com-20121103171627-7mvvn13494ofbbh0 --- addons/account/account_cash_statement.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index 9a5eb93286f..c1f30824461 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -289,13 +289,13 @@ class account_cash_statement(osv.osv): super(account_cash_statement, self).button_confirm_bank(cr, uid, ids, context=context) absl_proxy = self.pool.get('account.bank.statement.line') - TABLES = (('Profit', 'profit_account_id'), ('Loss', 'loss_account_id'),) + TABLES = ((_('Profit'), 'profit_account_id'), (_('Loss'), 'loss_account_id'),) for obj in self.browse(cr, uid, ids, context=context): if obj.difference == 0.0: continue - for item_label, item_account in TALBES: + for item_label, item_account in TABLES: if getattr(obj.journal_id, item_account): raise osv.except_osv(_('Error!'), _('There is no %s Account on the journal %s.') % (item_label, obj.journal_id.name,))