コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
415 ビュー

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

アバター
破棄

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.

著作者

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.

著作者 最善の回答

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.

アバター
破棄
最善の回答

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.

アバター
破棄
関連投稿 返信 ビュー 活動
3
10月 20
5227
0
3月 15
2956
2
3月 15
6201
2
4月 22
4051
3
4月 25
903