Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
1086 Lượt xem

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

Ảnh đại diện
Huỷ bỏ

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.

Tác giả

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.

Tác giả Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 10 20
5746
0
thg 3 15
3330
2
thg 3 15
6695
2
thg 4 22
4462
1
thg 7 25
613