Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
577 Widoki

In my custom model I tried to create a function that will create an invoice. However when I tried to Post the invoice using this code


invoice = self.env['account.move'].create(vals)

invoice.action_post()


The record was actual created and it was Posted but the amount due is 0. All other computations in the invoice are correct. What seems to be the problem here? Thanks in advance

Awatar
Odrzuć

Post the rest of your code, the contents of vals, and the types of each of the accounts you are using, there could be many things and readers can not guess from the information you have shared.

Autor

Thanks for pointing out. This is the code snippet base on the query above.

def create_bill_invoiced(self, invoice_id, agent, vendor_name, amount=20000):
    # agent is a custom model
 
    # Create a service-type product template
    product = self.env['product.template'].create({
        'name': f"Bill from {vendor_name}",
        'list_price': amount,
        'type': 'service',
        'sale_ok': False,
        'purchase_ok': True,
        'company_id': agent.company_id.id,
        'taxes_id': [],
        'supplier_taxes_id': [],
    })

    variant = product.product_variant_id
    if not variant:
        return False

    # Build a single invoice line for the variant
    invoice_line = (0, 0, {
        'product_id': variant.id,
        'name': variant.name,
        'quantity': 1,
        'price_unit': amount,
        'account_id': self.get_product_account(product_id=variant.id, company_id=agent.company_id.id),
    })

    # Create the bill (vendor invoice)
    bill_invoiced = self.env['account.move'].create({
        'move_type': 'in_invoice',
        'partner_id': agent.portal_user.partner_id.id,
        'invoice_date': fields.Date.today(),
        'invoice_date_due': fields.Date.today() + timedelta(days=5),
        'invoice_line_ids': [invoice_line],
        'ref': f"Related Invoice ID: {invoice_id}",
    })

    bill_invoiced.action_post()
    return bill_invoiced


The

bill_invoiced = self.env['account.move'].create

 actually created a record and it is Posted automatically by

bill_invoiced.action_post()

.However the amount due is 0. I checked the other values and it seems the amount residual is also 0. Other values such as Total amount and subtotals are correct. I tried to manually reset the record to draft and post it again. It works, but I should be able to do this via code.

Autor Najlepsza odpowiedź

Update, I found out at the Journal items section showed only 1 item with account name Income. There suppose to be 2 (Income and Account Payable) with correct amount values for debit and credit. However, still dont know what to do next.

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

The field "Amount Residual" is a computed field. To ensure it reflects the correct value, please verify the following:

  1. You're correctly passing the invoice_line_ids when creating the invoice—make sure each line includes the product, quantity, price, and account.
  2. The correct accounts are configured for the products and are included in the invoice lines.
  3. There is no custom code overriding or interfering with the computation of the residual amount.
  4. The taxes and journal are properly configured and correctly applied to the invoice.


Hope it helps.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
paź 20
5288
0
mar 15
3032
2
mar 15
6305
2
kwi 22
4097
3
kwi 25
1012