def action_generate_bill(self):
# Assuming you have necessary information for creating the invoice
invoice_data = {
# 'payment_reference': self.type_id.id, # Replace with the actual partner field in your model
# 'partner_id': self.user_id.id, # Replace with other necessary fields
'move_type': 'out_invoice' # if it is an invoice otherwise in_invoice if it is a bill
# Add more fields as needed
}
# Create a new invoice
new_invoice = self.env['account.move'].create(invoice_data)
# Find the corresponding baba.approve record based on type_id
approve_record = self.env['baba.approval'].search([('type_id', '=', self.type_id.id)])
# If a matching record is found, create invoice lines with adjusted amounts
if approve_record:
for line in new_invoice.invoice_line_ids:
line.price_unit -= approve_record.approve_amount
# Open the form view of the newly created invoice
action = {
'type': 'ir.actions.act_window',
'res_model': 'account.move',
'view_mode': 'form',
'res_id': new_invoice.id,
}
return action
here is my function when i clcik on this button then it take me to account.nove invoice
i have add a a many2one field in both model to tract the same
class MultiApproval(models.Model):
_name = 'baba.approval'
type_id = fields.Many2one(
string="Type", comodel_name="baba.approval.type", required=True)
class AccountAmount(models.Model):
_inherit = "account.move"
type_id = fields.Many2one(
string="Type", comodel_name="baba.approval.type", required=True)
in my baba.approval model there is a field
approve_amount = fields.Float('Approved Amount') here i define the amount now i want when type_id is same in the both model then what price i add in the account.move model amount_total filed value is subtraction from approve_amount
examle is my approve amount is 5000 and in the same type_id amount_total is 3000 then my approve_amount automatically will be 2000 when this invoice is in posted state
how i do this
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Akuntansi
- Inventaris
- PoS
- Project
- MRP
Pertanyaan ini telah diberikan tanda
2
Replies
787
Tampilan
hi james
thanks for your support
type_id = fields.Many2one(
string="Type", comodel_name="baba.approval.type", required=True)
approve_amount = fields.Float('Approved Amount',compute='_compute_approve_amount')
@api.depends('type_id')
def _compute_approve_amount(self):
if self.new_invoice.state == 'posted' and self.new_invoice and self.type_id == self.new_invoice.type_id:
self.approve_amount = self.approve_amount - self.new_invoice.amount_total
def action_generate_bill(self):
# Assuming you have necessary information for creating the invoice
invoice_data = {
# 'payment_reference': self.type_id.id, # Replace with the actual partner field in your model
# 'partner_id': self.user_id.id, # Replace with other necessary fields
'move_type': 'out_invoice' # if it is an invoice otherwise in_invoice if it is a bill
# Add more fields as needed
}
# Create a new invoice
new_invoice = self.env['account.move'].create(invoice_data)
# Find the corresponding baba.approve record based on type_id
approve_record = self.env['baba.approval'].search([('type_id', '=', self.type_id.id)])
# If a matching record is found, create invoice lines with adjusted amounts
if approve_record:
for line in new_invoice.invoice_line_ids:
line.price_unit -= approve_record.approve_amount
# Open the form view of the newly created invoice
action = {
'type': 'ir.actions.act_window',
'res_model': 'account.move',
'view_mode': 'form',
'res_id': new_invoice.id,
}
return action
i have try this but its not wokring
here i want from my approve_amount field of same type_Id in account.move model amount_total will be substraction when the innvoice is in posted state
Hi Deen
check the code following,
assign created new_invoice record to a many2one of 'account.move' in your model
class MultiApproval(models.Model):
_name = 'baba.approval'
type_id = fields.Many2one(
string="Type", comodel_name="baba.approval.type", required=True)
approve_amount = fields.Float('Approved Amount',compute='_compute_approve_amount')
@api.depends('type_id')
def _compute_approve_amount(self):
if self.new_invoice.state == 'posted' and self.new_invoice and self.type_id == self.new_invoice.type_id:
self.approve_amount = self.approve_amount - self.new_invoice.amount_total
Regards
Menikmati diskusi? Jangan hanya membaca, ikuti!
Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!
Daftar