Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
1 Svar
970 Visninger
class BillAdjustment(models.Model):
_name = 'bill.adjustment'
_description = 'Bill And Adjustment'
invoice_id = fields.Many2one('account.move', string='Invoice')
label_amount_ids = fields.One2many('bill.adjustment.items', 'bill_id', string='Label and Amount Lines')

def open_invoice_form(self):
"""Generate invoice for reservation payment"""
account_move_obj = self.env["account.move"]
for reservation in self:
vals = {

"move_type": "out_invoice",
}
invoice_line = []
for line in reservation.label_amount_ids:
invoice_line_vals = {
"account_id": "",
"quantity": 1.000, # Assuming the quantity is always 1 for a reservation
}
invoice_line.append((0, 0, invoice_line_vals))

if not invoice_line:
raise UserError(
_("Cannot create invoice without any invoice lines. Please add at least one invoice line."))

vals.update({"invoice_line_ids": invoice_line})

# Create the invoice
account_invoice_id = self.env["account.move"].create(vals)
account_invoice_id.action_post()

# Open the invoice form view after creating the invoice
invoice_obj = self.env.ref("account.view_move_form")
return {
"name": _("Generate Bill"),
"view_mode": "form",
"res_model": "account.move",
"view_id": invoice_obj.id,
"type": "ir.actions.act_window",
"nodestroy": True,
"target": "current",
"res_id": account_invoice_id.id,
"context": {},
}
class JobSummaryItems(models.Model):
_name = 'bill.adjustment.items'
_description = 'Job Summary Items'bill_id = fields.Many2one('bill.adjustment', string='Bill Adjustment')

here i want when o click on open_invoice_formbutton then it take me to account.move model bill menu view but now wwhen i clcik on this it give me
The field 'Customer' is required, please complete it to validate the Customer Invoice.
how i solve this
if you know please help he
thanks







Avatar
Kassér
Bedste svar

Hi,
When the 'open_invoice_form' button is clicked, it triggers the creation of an 'account.move' record with the 'move_type' set to 'out_invoice'. To fulfill the validation for a Customer Invoice, please ensure that the 'vals' dictionary includes the 'partner_id' as it is required for the mandatory 'Customer' field. Kindly add the 'partner_id' within the 'vals' dictionary to validate the Customer Invoice appropriately.

Hope it helps

Avatar
Kassér