mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
[FIX] completion rules + to ensure minimum default and take in account the profile account as master value
This commit is contained in:
@@ -137,14 +137,16 @@ class AccountStatementCompletionRule(orm.Model):
|
|||||||
inv_obj = self.pool.get('account.invoice')
|
inv_obj = self.pool.get('account.invoice')
|
||||||
if inv_type == 'supplier':
|
if inv_type == 'supplier':
|
||||||
type_domain = ('in_invoice', 'in_refund')
|
type_domain = ('in_invoice', 'in_refund')
|
||||||
|
number_field = 'supplier_invoice_number'
|
||||||
elif inv_type == 'customer':
|
elif inv_type == 'customer':
|
||||||
type_domain = ('out_invoice', 'out_refund')
|
type_domain = ('out_invoice', 'out_refund')
|
||||||
|
number_field = 'number'
|
||||||
else:
|
else:
|
||||||
raise osv.except_osv(_('System error'),
|
raise osv.except_osv(_('System error'),
|
||||||
_('Invalid invoice type for completion: %') % inv_type)
|
_('Invalid invoice type for completion: %') % inv_type)
|
||||||
|
|
||||||
inv_id = inv_obj.search(cr, uid,
|
inv_id = inv_obj.search(cr, uid,
|
||||||
[('supplier_invoice_number', '=', st_line.ref),
|
[(number_field , '=', st_line.ref),
|
||||||
('type', 'in', type_domain)],
|
('type', 'in', type_domain)],
|
||||||
context=context)
|
context=context)
|
||||||
if inv_id:
|
if inv_id:
|
||||||
@@ -167,8 +169,11 @@ class AccountStatementCompletionRule(orm.Model):
|
|||||||
inv = self._find_invoice(cr, uid, st_line, inv_type, context=context)
|
inv = self._find_invoice(cr, uid, st_line, inv_type, context=context)
|
||||||
if inv:
|
if inv:
|
||||||
res = {'partner_id': inv.partner_id.id,
|
res = {'partner_id': inv.partner_id.id,
|
||||||
'account_id': inv.account_id,
|
'account_id': inv.account_id.id,
|
||||||
'type': inv_type}
|
'type': inv_type}
|
||||||
|
override_acc = st_line.statement_id.profile_id.receivable_account_id
|
||||||
|
if override_acc:
|
||||||
|
res['account_id'] = override_acc.id
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def get_from_ref_and_supplier_invoice(self, cr, uid, line_id, context=None):
|
def get_from_ref_and_supplier_invoice(self, cr, uid, line_id, context=None):
|
||||||
@@ -330,7 +335,7 @@ class AccountStatementCompletionRule(orm.Model):
|
|||||||
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
st_line = st_obj.browse(cr, uid, line_id, context=context)
|
||||||
if st_line:
|
if st_line:
|
||||||
sql = "SELECT id FROM res_partner WHERE name ~* %s"
|
sql = "SELECT id FROM res_partner WHERE name ~* %s"
|
||||||
pattern = ".*%s.*" % re.escape(st_line.label)
|
pattern = ".*%s.*" % re.escape(st_line.name)
|
||||||
cr.execute(sql, (pattern,))
|
cr.execute(sql, (pattern,))
|
||||||
result = cr.fetchall()
|
result = cr.fetchall()
|
||||||
if not result:
|
if not result:
|
||||||
@@ -408,7 +413,14 @@ class AccountStatementLine(orm.Model):
|
|||||||
# Ask the rule
|
# Ask the rule
|
||||||
vals = profile_obj._find_values_from_rules(
|
vals = profile_obj._find_values_from_rules(
|
||||||
cr, uid, rules, line.id, context)
|
cr, uid, rules, line.id, context)
|
||||||
# Merge the result
|
# get the default
|
||||||
|
if not vals:
|
||||||
|
vals= st_obj.get_values_for_line(cr,
|
||||||
|
uid,
|
||||||
|
profile_id=line.statement_id.profile_id.id,
|
||||||
|
line_type=line.type,
|
||||||
|
amount=line.amount,
|
||||||
|
context=context)
|
||||||
res[line.id].update(vals)
|
res[line.id].update(vals)
|
||||||
except ErrorTooManyPartner, exc:
|
except ErrorTooManyPartner, exc:
|
||||||
msg = "Line ID %s had following error: %s" % (line.id, exc.value)
|
msg = "Line ID %s had following error: %s" % (line.id, exc.value)
|
||||||
|
|||||||
@@ -186,6 +186,9 @@ class AccountStatementProfil(Model):
|
|||||||
statement_id = statement_obj.create(cr, uid,
|
statement_id = statement_obj.create(cr, uid,
|
||||||
{'profile_id': prof.id},
|
{'profile_id': prof.id},
|
||||||
context=context)
|
context=context)
|
||||||
|
if prof.receivable_account_id:
|
||||||
|
account_receivable, account_payable = prof.receivable_account_id.id
|
||||||
|
else:
|
||||||
account_receivable, account_payable = statement_obj.get_default_pay_receiv_accounts(
|
account_receivable, account_payable = statement_obj.get_default_pay_receiv_accounts(
|
||||||
cr, uid, context)
|
cr, uid, context)
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user