콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
1159 화면

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
5785
0
3월 15
3393
2
3월 15
6717
2
4월 22
4505
1
7월 25
716