Skip to Content
Menu
This question has been flagged

I am trying to upgrade custom module in odoo14 to odoo16
the code in custom 14 override  _prepare_move_line_default_vals function an d made changes in it this is the code:


def _prepare_move_line_default_vals(self, write_off_line_vals=None):
''' Prepare the dictionary to create the default account.move.lines for the current payment.
:param write_off_line_vals: Optional dictionary to create a write-off account.move.line easily containing:
* amount: The amount to be added to the counterpart amount.
* name: The label to set on the line.
* account_id: The account on which create the write-off.
:return: A list of python dictionary to be passed to the account.move.line's 'create' method.
'''
self
.ensure_one()
write_off_line_vals = write_off_line_vals or {}

if not self.journal_id.payment_debit_account_id or not self.journal_id.payment_credit_account_id:
raise UserError(_(
"You can't create a new payment without an outstanding payments/receipts account set on the %s journal.",
self
.journal_id.display_name))

# Compute amounts.
write_off_amount = write_off_line_vals.get('amount', 0.0)

if self.payment_type == 'inbound':
# Receive money.
counterpart_amount = -self.amount
write_off_amount *= -1
elif self
.payment_type == 'outbound':
# Send money.
counterpart_amount = self.amount
else:
counterpart_amount = 0.0
write_off_amount = 0.0

balance = counterpart_amount / self.currency_rate
counterpart_amount_currency = counterpart_amount
write_off_balance = self.currency_id._convert(write_off_amount, self.company_id.currency_id, self.company_id, self.date)
write_off_amount_currency = write_off_amount
currency_id = self.currency_id.id

if self.is_internal_transfer:
if self.payment_type == 'inbound':
liquidity_line_name = _('Transfer to %s', self.journal_id.name)
else: # payment.payment_type == 'outbound':
liquidity_line_name = _('Transfer from %s', self.journal_id.name)
else:
liquidity_line_name = self.payment_reference

# Compute a default label to set on the journal items.

payment_display_name = {
'outbound-customer': _("Customer Reimbursement"),
'inbound-customer'
: _("Customer Payment"),
'outbound-supplier'
: _("Vendor Payment"),
'inbound-supplier'
: _("Vendor Reimbursement"),
}

default_line_name = self.env['account.move.line']._get_default_line_name(
_("Internal Transfer") if self.is_internal_transfer else payment_display_name['%s-%s' % (self.payment_type, self.partner_type)],
self
.amount,
self
.currency_id,
self
.date,
partner
=self.partner_id,
)

line_vals_list = [
# Liquidity line.
{
'name': liquidity_line_name or default_line_name,
'date_maturity'
: self.date,
'amount_currency'
: -counterpart_amount_currency,
'currency_id'
: currency_id,
'debit'
: balance < 0.0 and -balance or 0.0,
'credit'
: balance > 0.0 and balance or 0.0,
'partner_id'
: self.partner_id.id,
'account_id'
: self.journal_id.payment_debit_account_id.id if balance < 0.0 else self.journal_id.payment_credit_account_id.id,
},
# Receivable / Payable.
{
'name': self.payment_reference or default_line_name,
'date_maturity'
: self.date,
'amount_currency'
: counterpart_amount_currency + write_off_amount_currency if currency_id else 0.0,
'currency_id'
: currency_id,
'debit'
: balance + write_off_balance > 0.0 and balance + write_off_balance or 0.0,
'credit'
: balance + write_off_balance < 0.0 and -balance - write_off_balance or 0.0,
'partner_id'
: self.partner_id.id,
'account_id'
: self.destination_account_id.id,
},
]
if write_off_balance:
# Write-off line.
line_vals_list.append({
'name': write_off_line_vals.get('name') or default_line_name,
'amount_currency'
: -write_off_amount_currency,
'currency_id'
: currency_id,
'debit'
: write_off_balance < 0.0 and -write_off_balance or 0.0,
'credit'
: write_off_balance > 0.0 and write_off_balance or 0.0,
'partner_id'
: self.partner_id.id,
'account_id'
: write_off_line_vals.get('account_id'),
})
return line_vals_list




i need to convert it to odoo16 with the same changes in custom 14 how can i do that?
this the code of this function in odoo 16:
def _prepare_move_line_default_vals(self, write_off_line_vals=None):
''' Prepare the dictionary to create the default account.move.lines for the current payment.
:param write_off_line_vals: Optional list of dictionaries to create a write-off account.move.line easily containing:
* amount: The amount to be added to the counterpart amount.
* name: The label to set on the line.
* account_id: The account on which create the write-off.
:return: A list of python dictionary to be passed to the account.move.line's 'create' method.
'''
self
.ensure_one()
write_off_line_vals = write_off_line_vals or {}

if not self.outstanding_account_id:
raise UserError(_(
"You can't create a new payment without an outstanding payments/receipts account set either on the company or the %s payment method in the %s journal.",
self
.payment_method_line_id.name, self.journal_id.display_name))

# Compute amounts.
write_off_line_vals_list = write_off_line_vals or []
write_off_amount_currency = sum(x['amount_currency'] for x in write_off_line_vals_list)
write_off_balance = sum(x['balance'] for x in write_off_line_vals_list)

if self.payment_type == 'inbound':
# Receive money.
liquidity_amount_currency = self.amount
elif self.payment_type == 'outbound':
# Send money.
liquidity_amount_currency = -self.amount
else:
liquidity_amount_currency = 0.0

liquidity_balance = self.currency_id._convert(
liquidity_amount_currency,
self
.company_id.currency_id,
self
.company_id,
self
.date,
)
counterpart_amount_currency = -liquidity_amount_currency - write_off_amount_currency
counterpart_balance = -liquidity_balance - write_off_balance
currency_id = self.currency_id.id

# Compute a default label to set on the journal items.
liquidity_line_name = ''.join(x[1] for x in self._get_liquidity_aml_display_name_list())
counterpart_line_name = ''.join(x[1] for x in self._get_counterpart_aml_display_name_list())

line_vals_list = [
# Liquidity line.
{
'name': liquidity_line_name,
'date_maturity'
: self.date,
'amount_currency'
: liquidity_amount_currency,
'currency_id'
: currency_id,
'debit'
: liquidity_balance if liquidity_balance > 0.0 else 0.0,
'credit'
: -liquidity_balance if liquidity_balance < 0.0 else 0.0,
'partner_id'
: self.partner_id.id,
'account_id'
: self.outstanding_account_id.id,
},
# Receivable / Payable.
{
'name': counterpart_line_name,
'date_maturity'
: self.date,
'amount_currency'
: counterpart_amount_currency,
'currency_id'
: currency_id,
'debit'
: counterpart_balance if counterpart_balance > 0.0 else 0.0,
'credit'
: -counterpart_balance if counterpart_balance < 0.0 else 0.0,
'partner_id'
: self.partner_id.id,
'account_id'
: self.destination_account_id.id,
},
]
return line_vals_list + write_off_line_vals_list

Avatar
Discard

you are having and issue or something with your code update?

Related Posts Replies Views Activity
0
Sep 23
1421
1
Jun 23
2564
1
May 25
1431
1
Apr 25
2677
1
Apr 25
3455