If you want to set the expected payment data in Odoo follow the following code :
if vals.get('expected_pay_date') and self.invoice_id:
msg = _('New expected payment date: ') + vals['expected_pay_date'] + '.\n' + vals.get('internal_note', '')
self.invoice_id.message_post(body=msg) #TODO: check it is an internal note (not a regular email)!
#when making a reconciliation on an existing liquidity journal item, mark the payment as reconciled
if 'statement_id' in vals and self.payment_id:
# In case of an internal transfer, there are 2 liquidity move lines to match with a bank statement
if all(line.statement_id for line in self.payment_id.move_line_ids.filtered(lambda r: r.id != self.id and r.account_id.internal_type=='liquidity')):
self.payment_id.state = 'reconciled'
result = super(AccountMoveLine, self).write(vals)
if self._context.get('check_move_validity', True):
move_ids = set()
for line in self:
if line.move_id.id not in move_ids:
move_ids.add(line.move_id.id)
self.env['account.move'].browse(list(move_ids))._post_validate()
return result
@api.multi
def _update_check(self):
""" Raise Warning to cause rollback if the move is posted, some entries are reconciled or the move is older than the lock date"""
move_ids = set()
for line in self:
err_msg = _('Move name (id): %s (%s)') % (line.move_id.name, str(line.move_id.id))
if line.move_id.state != 'draft':
raise UserError(_('You cannot do this modification on a posted journal entry, you can just change some non legal fields. You must revert the journal entry to cancel it.\n%s.') % err_msg)
if line.reconciled:
raise UserError(_('You cannot do this modification on a reconciled entry. You can just change some non legal fields or you must unreconcile first.\n%s.') % err_msg)
if line.move_id.id not in move_ids:
move_ids.add(line.move_id.id)
self.env['account.move'].browse(list(move_ids))._check_lock_date()
return True
@api.multi
@api.depends('ref', 'move_id')
def name_get(self):
result = []
for line in self:
if line.ref:
result.append((line.id, (line.move_id.name or '') + '(' + line.ref + ')'))
else:
result.append((line.id, line.move_id.name))
return result
@api.model
def compute_amount_fields(self, amount, src_currency, company_currency):
""" Helper function to compute value for fields debit/credit/amount_currency based on an amount and the currencies given in parameter"""
amount_currency = False
if src_currency and src_currency != company_currency:
amount_currency = amount
amount = src_currency.with_context(self._context).compute(amount, company_currency)
debit = amount > 0 and amount or 0.0
credit = amount < 0 and -amount or 0.0
return debit, credit, amount_currency
@api.multi
def create_analytic_lines(self):
""" Create analytic items upon validation of an account.move.line having an analytic account. This
method first remove any existing analytic item related to the line before creating any new one.
"""
for obj_line in self:
if obj_line.analytic_account_id:
if obj_line.analytic_line_ids:
obj_line.analytic_line_ids.unlink()
vals_line = obj_line._prepare_analytic_line()[0]
self.env['account.analytic.line'].create(vals_line)
@api.one
def _prepare_analytic_line(self):
""" Prepare the values used to create() an account.analytic.line upon validation of an account.move.line having
an analytic account. This method is intended to be extended in other modules.
"""
return {
'name': self.name,
'date': self.date,
'account_id': self.analytic_account_id.id,
'unit_amount': self.quantity,
'product_id': self.product_id and self.product_id.id or False,
'product_uom_id': self.product_uom_id and self.product_uom_id.id or False,
'amount': (self.credit or 0.0) - (self.debit or 0.0),
'general_account_id': self.account_id.id,
'ref': self.ref,
'move_id': self.id,
'user_id': self.invoice_id.user_id.id or self._uid,
}
@api.model
def _query_get(self, domain=None):
context = dict(self._context or {})
domain = domain and safe_eval(domain) or []
date_field = 'date'
if context.get('aged_balance'):
date_field = 'date_maturity'
if context.get('date_to'):
domain += [(date_field, '<=', context['date_to'])]
if context.get('date_from'):
if not context.get('strict_range'):
domain += ['|', (date_field, '>=', context['date_from']), ('account_id.user_type_id.include_initial_balance', '=', True)]
elif context.get('initial_bal'):
domain += [(date_field, '<', context['date_from'])]
else:
domain += [(date_field, '>=', context['date_from'])]
if context.get('journal_ids'):
domain += [('journal_id', 'in', context['journal_ids'])]
state = context.get('state')
if state and state.lower() != 'all':
domain += [('move_id.state', '=', state)]
if context.get('company_id'):
domain += [('company_id', '=', context['company_id'])]
if 'company_ids' in context:
domain += [('company_id', 'in', context['company_ids'])]
where_clause = ""
where_clause_params = []
tables = ''
if domain:
query = self._where_calc(domain)
tables, where_clause, where_clause_params = query.get_sql()
return tables, where_clause, where_clause_params
0 Comment(s)