Update project_invoice.py

This commit is contained in:
zainab2097 2024-09-16 15:43:57 +03:00 committed by GitHub
parent 975235d9dd
commit 8dfb0788f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 4 deletions

View File

@ -10,6 +10,7 @@ class ProjectInvoice(models.Model):
name = fields.Char(string='Description',tracking=True,) name = fields.Char(string='Description',tracking=True,)
phase_id = fields.Many2one('project.phase', string="Stage") phase_id = fields.Many2one('project.phase', string="Stage")
partner_project_id = fields.Many2one('res.partner', string="Partner")
invoice_id = fields.Many2one('account.move', string="Invoice") invoice_id = fields.Many2one('account.move', string="Invoice")
amount = fields.Float(string="Invoice Amount", compute="compute_amount", store=True,tracking=True,) amount = fields.Float(string="Invoice Amount", compute="compute_amount", store=True,tracking=True,)
to_invoice = fields.Boolean(string="To invoice", default=False) to_invoice = fields.Boolean(string="To invoice", default=False)
@ -170,6 +171,9 @@ class ProjectInvoice(models.Model):
invoice_vals = {} invoice_vals = {}
self.ensure_one() self.ensure_one()
journal = self.env['account.move'].sudo().with_context(default_move_type='out_invoice')._get_default_journal() journal = self.env['account.move'].sudo().with_context(default_move_type='out_invoice')._get_default_journal()
# Checking for a partner in the current model and defaulting if not available
partner_id = self.partner_project_id.id if self.partner_project_id else (self.invoice_type == 'consultant' and self.project_id.consultant_id.id or self.project_id.partner_id.id)
if not journal: if not journal:
raise UserError(_('Please define an accounting sales journal for the company %s (%s).') % ( raise UserError(_('Please define an accounting sales journal for the company %s (%s).') % (
self.company_id.name, self.company_id.id)) self.company_id.name, self.company_id.id))
@ -179,7 +183,7 @@ class ProjectInvoice(models.Model):
'move_type': 'out_invoice', 'move_type': 'out_invoice',
'currency_id': self.currency_id.id, 'currency_id': self.currency_id.id,
'ref': self.project_id.project_no, 'ref': self.project_id.project_no,
'partner_id': self.invoice_type == 'consultant' and self.project_id.consultant_id.id or self.project_id.partner_id.id , 'partner_id':partner_id,
'partner_shipping_id': self.project_id.partner_id.id, 'partner_shipping_id': self.project_id.partner_id.id,
'partner_bank_id': self.company_id.partner_id.bank_ids.filtered( 'partner_bank_id': self.company_id.partner_id.bank_ids.filtered(
lambda bank: bank.company_id.id in (self.company_id.id, False))[:1].id, lambda bank: bank.company_id.id in (self.company_id.id, False))[:1].id,
@ -196,7 +200,7 @@ class ProjectInvoice(models.Model):
'move_type': 'in_invoice', 'move_type': 'in_invoice',
'currency_id': self.currency_id.id, 'currency_id': self.currency_id.id,
'ref': self.project_id.project_no, 'ref': self.project_id.project_no,
'partner_id': self.invoice_type == 'consultant' and self.project_id.consultant_id.id or self.project_id.partner_id.id , 'partner_id':partner_id,
'partner_shipping_id': self.project_id.partner_id.id, 'partner_shipping_id': self.project_id.partner_id.id,
'partner_bank_id': self.company_id.partner_id.bank_ids.filtered( 'partner_bank_id': self.company_id.partner_id.bank_ids.filtered(
lambda bank: bank.company_id.id in (self.company_id.id, False))[:1].id, lambda bank: bank.company_id.id in (self.company_id.id, False))[:1].id,
@ -286,8 +290,8 @@ class ProjectInvoiceLine(models.Model):
project_invoice_id = fields.Many2one('project.invoice', string='Project Invoice', required=True, ondelete='cascade', project_invoice_id = fields.Many2one('project.invoice', string='Project Invoice', required=True, ondelete='cascade',
index=True, copy=False) index=True, copy=False)
product_id = fields.Many2one('product.product',digits='Product Unit of Measure', string='Product') product_id = fields.Many2one('product.product',string='Product')
product_uom_qty = fields.Float(string='Percentage', required=True, default=0.0) product_uom_qty = fields.Float(string='Percentage',digits='Product Unit of Measure',required=True, default=0.0)
amount = fields.Monetary("Amount") amount = fields.Monetary("Amount")
product_uom = fields.Many2one('uom.uom', string='Unit of Measure', ) product_uom = fields.Many2one('uom.uom', string='Unit of Measure', )
price_unit = fields.Float('Unit Price', digits='Project Amount') price_unit = fields.Float('Unit Price', digits='Project Amount')