I am creating a membership invoice, with a float quantity for a certain purpose
I am trying to pass a float value as quantity to invoice line..when it passes the the price_subtotal is not updating properly. Instead the price_unit changes to round the price_subtotal....The code here
@api.model_create_multi
def create(self, vals_list):
lines = super(AccountMoveLine, self).create(vals_list)
print('create value lines', lines)
print('create value list', vals_list)
# product = self.env['product.product'].browse(
# vals.get('product_id', False)
# )
to_process = lines.filtered(lambda line: line.move_id.type == 'out_invoice'
and line.product_id.membership and line.product_id.membership_prorate)
invoice_line_vals = []
for line in to_process:
if line.product_id.membership_prorate:
line_vals = self._prepare_invoice_line_prorate_vals(
line)
print('line_vals prorate', line_vals)
if line_vals:
date_from = line_vals.pop('date_from')
for vals in vals_list :
# val['quantity'] = line_vals['quantity']
# if val['move_id']
# val.update({"quantity": line_vals['quantity']})
vals.update(line_vals)###########################IMPORTANT##########
currency = self.env['res.currency'].browse(
vals.get'cuency_id'))
partner = self.env['res.partner'].browse(vals.get('partner_id'))
taxes = self.resolve_2many_commands('tax_ids', vals.get('tax_ids', []), fields=['id'])
tax_ids = set(tax['id'] for tax in taxes)
taxes = self.env['account.tax'].browse(tax_ids)
move = self.env['account.move'].browse(vals['move_id'])
vals.update(self._get_price_total_and_subtotal_model(
vals.get('price_unit'),
vals.get('quantity'),
vals.get('discount', 0.0),
currency,
self.env['product.product'].browse( vals.get('product_id')),
partner,
taxes,
move.type,
))
move.with_context(
check_move_validity=False)._recompute_dynamic_lines\
(recompute_all_taxes=True)
# line.write(vals)
self.quantity = line_vals['quantity']
# invoice_line_vals.append(line_vals)
# date_from = invoice_line_vals['date_from']
# line.write(invoice_line_vals)#was there
print('vals_list[0]',vals_list[0])
line.write(vals_list[0])#updated there
return lines
Eg: The unit price is 1 and the quantity is 0.86, but it recalculate as below
This is the vals_list updated
for lines = super(AccountMoveLine, self).create(vals_list)
create value list 2 [{'date': datetime.date(2020, 7, 21), 'journal_id': 1, 'company_id': 1, 'company_currency_id': 2, 'account_id': 19, 'name': 'Test Product', 'quantity': 0.85, 'price_unit': 1.0, 'discount': 0.0, 'debit': 0.0, 'credit': 1.0, 'balance': -1.0, 'amount_currency': 0.0, 'price_subtotal': 0.85, 'price_total': 0.85, 'currency_id': False, 'partner_id': 44, 'product_id': 78, 'payment_id': False, 'tax_ids': [(6, 0, [])], 'tax_repartition_line_id': False, 'tag_ids': [(6, 0, [])], 'matched_debit_ids': [(6, 0, [])], 'matched_credit_ids': [(6, 0, [])], 'analytic_line_ids': [(6, 0, [])], 'recompute_tax_line': False, 'display_type': False, 'is_rounding_line': False, 'exclude_from_invoice_tab': False, 'always_set_currency_id': 2, 'sale_line_ids': [(6, 0, [])], 'move_id': 113, 'tax_exigible': True}, {'company_id': 1, 'company_currency_id': 2, 'account_id': 6, 'name': '', 'quantity': 0.85, 'price_unit': -1.0, 'discount': 0.0, 'debit': 1.0, 'credit': 0.0, 'balance': 1.0, 'amount_currency': 0.0, 'price_subtotal': -0.85, 'price_total': -0.85, 'date_maturity': datetime.date(2020, 7, 21), 'currency_id': False, 'partner_id': 44, 'product_id': False, 'tax_ids': [(6, 0, [])], 'exclude_from_invoice_tab': True, 'always_set_currency_id': 2, 'sale_line_ids': [(6, 0, [])], 'move_id': 113, 'tax_exigible': True}]
any solution for this price_subtotal fix?