diff --git a/odex25_project/project_base/models/project_invoice.py b/odex25_project/project_base/models/project_invoice.py index 7e995fd0b..b7c95ba76 100644 --- a/odex25_project/project_base/models/project_invoice.py +++ b/odex25_project/project_base/models/project_invoice.py @@ -10,6 +10,7 @@ class ProjectInvoice(models.Model): name = fields.Char(string='Description',tracking=True,) 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") amount = fields.Float(string="Invoice Amount", compute="compute_amount", store=True,tracking=True,) to_invoice = fields.Boolean(string="To invoice", default=False) @@ -170,6 +171,9 @@ class ProjectInvoice(models.Model): invoice_vals = {} self.ensure_one() 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: raise UserError(_('Please define an accounting sales journal for the company %s (%s).') % ( self.company_id.name, self.company_id.id)) @@ -179,7 +183,7 @@ class ProjectInvoice(models.Model): 'move_type': 'out_invoice', 'currency_id': self.currency_id.id, '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_bank_id': self.company_id.partner_id.bank_ids.filtered( 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', 'currency_id': self.currency_id.id, '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_bank_id': self.company_id.partner_id.bank_ids.filtered( 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', index=True, copy=False) - product_id = fields.Many2one('product.product',digits='Product Unit of Measure', string='Product') - product_uom_qty = fields.Float(string='Percentage', required=True, default=0.0) + product_id = fields.Many2one('product.product',string='Product') + product_uom_qty = fields.Float(string='Percentage',digits='Product Unit of Measure',required=True, default=0.0) amount = fields.Monetary("Amount") product_uom = fields.Many2one('uom.uom', string='Unit of Measure', ) price_unit = fields.Float('Unit Price', digits='Project Amount') diff --git a/odex25_project/project_base/views/project_invoice_views.xml b/odex25_project/project_base/views/project_invoice_views.xml index 172829511..2b18c0f03 100644 --- a/odex25_project/project_base/views/project_invoice_views.xml +++ b/odex25_project/project_base/views/project_invoice_views.xml @@ -30,6 +30,7 @@ +