[MERGE] pos: fix multicompany bugs
(this is also an attempt to fix history breakage due to fp-style merge) bzr revid: odo@openerp.com-20121105111609-yuaw6wu6jd1ar2a1
This commit is contained in:
commit
ef3210031d
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
@ -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,))
|
||||
|
|
|
@ -296,49 +296,55 @@ 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)
|
||||
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:
|
||||
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,
|
||||
'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)
|
||||
|
||||
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 +396,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)
|
||||
|
||||
|
@ -493,17 +499,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 +718,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 +741,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 +766,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):
|
||||
|
|
|
@ -152,7 +152,7 @@
|
|||
|
||||
<record model="workflow.transition" id="trans_open_to_close">
|
||||
<field name="act_from" ref="act_open" />
|
||||
<field name="act_to" ref="act_close" />
|
||||
<field name="act_to" ref="act_closing_control" />
|
||||
<field name="signal">close</field>
|
||||
<field name="condition">cash_control == False</field>
|
||||
</record>
|
||||
|
@ -163,5 +163,13 @@
|
|||
<field name="signal">close</field>
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="trans_closing_control_to_close_no_control">
|
||||
<field name="act_from" ref="act_closing_control" />
|
||||
<field name="act_to" ref="act_close" />
|
||||
<field name="condition">cash_control == False</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue