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'
class JobSummaryItems(models.Model):
_name = 'bill.adjustment.items'
_description = 'Job Summary Items'
bill_id = fields.Many2one('bill.adjustment', string='Bill Summary')
item_name = fields.Char('Item Name')
quantity = fields.Float('Quantity')
unit_price = fields.Float('Unit Price')
total = fields.Float('Total', compute='_compute_total', store=True)
bill_id = fields.Many2one('bill.adjustment', string='Bill Adjustment')
@api.depends('quantity', 'unit_price')
def _compute_total(self):
for record in self:
record.total = record.quantity * record.unit_price
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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Proyecto
- MRP
Se marcó esta pregunta
Hi,
You can try this code,
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",
"partner_id": reservation.invoice_id.partner_id.id, # Set partner_id from the original invoice
}
invoice_line = []
for line in reservation.label_amount_ids:
invoice_line_vals = {
"account_id": "", # Set your account_id
"quantity": 1.000,
}
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": {},
}
Hope it helps
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
Inscribirse