From ede2f8b2aa5b14af09e698ab9d43142b4e10f401 Mon Sep 17 00:00:00 2001 From: Luke Zheng Date: Wed, 30 Mar 2016 15:43:22 +0800 Subject: [PATCH 1/5] [FIX] Fixed --- .../business_requirement_deliverable_default.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/business_requirement_deliverable_default/models/business_requirement_deliverable_default.py b/business_requirement_deliverable_default/models/business_requirement_deliverable_default.py index 8e733198d7..b77ddd6757 100644 --- a/business_requirement_deliverable_default/models/business_requirement_deliverable_default.py +++ b/business_requirement_deliverable_default/models/business_requirement_deliverable_default.py @@ -8,8 +8,20 @@ class BusinessRequirementDeliverable(models.Model): _inherit = "business.requirement.deliverable" def _prepare_resource_lines(self): - rl_data = self.product_id.sudo().resource_lines.copy_data() - rl_data = [(0, 0, item) for index, item in enumerate(rl_data)] + rl_data = [] + pricelist = self.project_id.get_closest_ancestor_pricelist() + res = self.product_id.sudo().resource_lines.copy_data() + for index, item in enumerate(res): + if pricelist: + product_obj = self.env['product.product'].browse( + item.get('product_id')) + product = product_obj.with_context( + quantity=item.get('qty'), + pricelist=pricelist.id, + uom=item.get('uom_id'), + ) + item.update({'sale_price_unit': product.price}) + rl_data.append((0, 0, item)) return rl_data @api.multi From a95034bec00315fac051bb104f8a6de5b69b90db Mon Sep 17 00:00:00 2001 From: Luke Zheng Date: Wed, 30 Mar 2016 15:56:15 +0800 Subject: [PATCH 2/5] [ADD] Get pricelist on project --- .DS_Store | Bin 10244 -> 10244 bytes .../models/business.py | 24 ++++++++++-------- .../models/project.py | 8 +++++- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.DS_Store b/.DS_Store index b857216dcd27e338109f3fb1bb1e1e13e1cfd373..dad2236ac6a406dc72aa15b56f8d2473c4c84b8b 100644 GIT binary patch delta 17 YcmZn(XbIS$C&I$Oz`(ZINaT_*04!?+g8%>k delta 17 XcmZn(XbIS$C&Ka{2sRsuToMKVN+}3= diff --git a/business_requirement_deliverable/models/business.py b/business_requirement_deliverable/models/business.py index 3820da9047..1740fa86f0 100644 --- a/business_requirement_deliverable/models/business.py +++ b/business_requirement_deliverable/models/business.py @@ -176,6 +176,7 @@ def product_id_change(self): unit_price = 0 product = self.product_id tax_ids = False + br = self.business_requirement_id if product: description = product.name_get()[0][1] uom_id = product.uom_id.id @@ -183,14 +184,14 @@ def product_id_change(self): tax_ids = product.taxes_id if product.description_sale: description += '\n' + product.description_sale - if self.business_requirement_id.project_id.pricelist_id and \ - self.business_requirement_id.partner_id and self.uom_id: + if br.project_id.pricelist_id and \ + br.partner_id and self.uom_id: + pricelist = br.project_id.get_closest_ancestor_pricelist() product = self.product_id.with_context( - lang=self.business_requirement_id.partner_id.lang, - partner=self.business_requirement_id.partner_id.id, + lang=br.partner_id.lang, + partner=br.partner_id.id, quantity=self.qty, - pricelist=self.business_requirement_id. - project_id.pricelist_id.id, + pricelist=pricelist.id, uom=self.uom_id.id, ) unit_price = product.price @@ -204,13 +205,14 @@ def product_uom_change(self): if not self.uom_id: self.price_unit = 0.0 return - if self.business_requirement_id.project_id.pricelist_id and \ - self.business_requirement_id.partner_id: + br = self.business_requirement_id + if br.project_id.pricelist_id and \ + br.partner_id: product = self.product_id.with_context( - lang=self.business_requirement_id.partner_id.lang, - partner=self.business_requirement_id.partner_id.id, + lang=br.partner_id.lang, + partner=br.partner_id.id, quantity=self.qty, - pricelist=self.business_requirement_id. + pricelist=br. project_id.pricelist_id.id, uom=self.uom_id.id, ) diff --git a/business_requirement_deliverable/models/project.py b/business_requirement_deliverable/models/project.py index 2698316551..76f762f10e 100644 --- a/business_requirement_deliverable/models/project.py +++ b/business_requirement_deliverable/models/project.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2016 Elico Corp (https://www.elico-corp.com). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import fields, models +from openerp import api, fields, models class Project(models.Model): @@ -15,3 +15,9 @@ class Project(models.Model): Deliverables linked to this project. Currency of the Deliverables will be the one from this pricelist.''' ) + + @api.multi + def get_closest_ancestor_pricelist(self): + for project in self: + pricelist = project.pricelist_id + return pricelist From 954cc0a22ab8f3c3b91ec56744968b63c5a0eeec Mon Sep 17 00:00:00 2001 From: Luke Zheng Date: Wed, 30 Mar 2016 16:11:08 +0800 Subject: [PATCH 3/5] [IMP] Use function to get pricelist on project model --- .../models/business.py | 14 +++++++------- .../models/business.py | 8 ++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/business_requirement_deliverable/models/business.py b/business_requirement_deliverable/models/business.py index 1740fa86f0..9d5515f0e7 100644 --- a/business_requirement_deliverable/models/business.py +++ b/business_requirement_deliverable/models/business.py @@ -206,14 +206,13 @@ def product_uom_change(self): self.price_unit = 0.0 return br = self.business_requirement_id - if br.project_id.pricelist_id and \ - br.partner_id: + if br.project_id and br.partner_id: + pricelist = br.project_id.get_closest_ancestor_pricelist() product = self.product_id.with_context( lang=br.partner_id.lang, partner=br.partner_id.id, quantity=self.qty, - pricelist=br. - project_id.pricelist_id.id, + pricelist=pricelist.id, uom=self.uom_id.id, ) self.unit_price = product.price @@ -240,16 +239,17 @@ class BusinessRequirement(models.Model): @api.depends( 'deliverable_lines', 'company_id.currency_id', - 'project_id.pricelist_id.currency_id', + 'project_id', ) def _compute_deliverable_total(self): for br in self: + pricelist = br.project_id.get_closest_ancestor_pricelist() if br.deliverable_lines: total_revenue_origin = sum( line.price_total for line in br.deliverable_lines) - if br.project_id.pricelist_id.currency_id: + if pricelist.currency_id: br.total_revenue = \ - br.project_id.pricelist_id.currency_id.compute( + pricelist.currency_id.compute( total_revenue_origin, br.company_id.currency_id) else: br.total_revenue = total_revenue_origin diff --git a/business_requirement_deliverable_cost/models/business.py b/business_requirement_deliverable_cost/models/business.py index e534daeeaa..c681049dd0 100644 --- a/business_requirement_deliverable_cost/models/business.py +++ b/business_requirement_deliverable_cost/models/business.py @@ -42,11 +42,13 @@ def product_id_change(self): resource.business_requirement_deliverable_id.project_id if deliverable_project.pricelist_id and \ deliverable_project.partner_id and resource.uom_id: + pricelist = \ + deliverable_project.get_closest_ancestor_pricelist() product = resource.product_id.with_context( lang=deliverable_project.partner_id.lang, partner=deliverable_project.partner_id.id, quantity=resource.qty, - pricelist=deliverable_project.pricelist_id.id, + pricelist=pricelist.id, uom=resource.uom_id.id, ) resource.sale_price_unit = product.price @@ -63,11 +65,13 @@ def product_uom_change(self): resource.business_requirement_deliverable_id.project_id if deliverable_project.pricelist_id and \ deliverable_project.partner_id: + pricelist = \ + deliverable_project.get_closest_ancestor_pricelist() product = resource.product_id.with_context( lang=deliverable_project.partner_id.lang, partner=deliverable_project.partner_id.id, quantity=resource.qty, - pricelist=deliverable_project.pricelist_id.id, + pricelist=pricelist.id, uom=resource.uom_id.id, ) resource.sale_price_unit = product.price From 11db4cc8a5ea6a93a46dba3b2fed504420e6a905 Mon Sep 17 00:00:00 2001 From: Luke Zheng Date: Wed, 30 Mar 2016 16:34:17 +0800 Subject: [PATCH 4/5] [IMP] Clean --- business_requirement_deliverable/models/business.py | 2 +- business_requirement_deliverable/models/project.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/business_requirement_deliverable/models/business.py b/business_requirement_deliverable/models/business.py index 9d5515f0e7..b976ed2861 100644 --- a/business_requirement_deliverable/models/business.py +++ b/business_requirement_deliverable/models/business.py @@ -247,7 +247,7 @@ def _compute_deliverable_total(self): if br.deliverable_lines: total_revenue_origin = sum( line.price_total for line in br.deliverable_lines) - if pricelist.currency_id: + if pricelist: br.total_revenue = \ pricelist.currency_id.compute( total_revenue_origin, br.company_id.currency_id) diff --git a/business_requirement_deliverable/models/project.py b/business_requirement_deliverable/models/project.py index 76f762f10e..8d55eb2c83 100644 --- a/business_requirement_deliverable/models/project.py +++ b/business_requirement_deliverable/models/project.py @@ -19,5 +19,6 @@ class Project(models.Model): @api.multi def get_closest_ancestor_pricelist(self): for project in self: - pricelist = project.pricelist_id + pricelist = self.env['product.pricelist'].browse( + project.pricelist_id.id) return pricelist From b3de9793835716c447df8abf65e2fdeaa44b647d Mon Sep 17 00:00:00 2001 From: Luke Zheng Date: Wed, 6 Apr 2016 18:41:02 +0800 Subject: [PATCH 5/5] [WIP] Check the pricelist logic --- .../models/business.py | 20 +++++++------- .../models/project.py | 7 ----- .../views/business_view.xml | 3 ++- .../models/business.py | 27 +++++++++---------- ...usiness_requirement_deliverable_default.py | 6 ++++- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/business_requirement_deliverable/models/business.py b/business_requirement_deliverable/models/business.py index b976ed2861..cf005371a4 100644 --- a/business_requirement_deliverable/models/business.py +++ b/business_requirement_deliverable/models/business.py @@ -177,6 +177,8 @@ def product_id_change(self): product = self.product_id tax_ids = False br = self.business_requirement_id + pricelist = br.get_estimation_pricelist(br.project_id) + partner = br.partner_id if product: description = product.name_get()[0][1] uom_id = product.uom_id.id @@ -184,12 +186,11 @@ def product_id_change(self): tax_ids = product.taxes_id if product.description_sale: description += '\n' + product.description_sale - if br.project_id.pricelist_id and \ + if pricelist and \ br.partner_id and self.uom_id: - pricelist = br.project_id.get_closest_ancestor_pricelist() product = self.product_id.with_context( - lang=br.partner_id.lang, - partner=br.partner_id.id, + lang=partner.lang, + partner=partner.id, quantity=self.qty, pricelist=pricelist.id, uom=self.uom_id.id, @@ -206,11 +207,12 @@ def product_uom_change(self): self.price_unit = 0.0 return br = self.business_requirement_id - if br.project_id and br.partner_id: - pricelist = br.project_id.get_closest_ancestor_pricelist() + pricelist = br.get_estimation_pricelist(br.project_id) + partner = br.partner_id + if pricelist and br.partner_id: product = self.product_id.with_context( - lang=br.partner_id.lang, - partner=br.partner_id.id, + lang=partner.lang, + partner=partner.id, quantity=self.qty, pricelist=pricelist.id, uom=self.uom_id.id, @@ -243,7 +245,7 @@ class BusinessRequirement(models.Model): ) def _compute_deliverable_total(self): for br in self: - pricelist = br.project_id.get_closest_ancestor_pricelist() + pricelist = br.get_estimation_pricelist(br.project_id) if br.deliverable_lines: total_revenue_origin = sum( line.price_total for line in br.deliverable_lines) diff --git a/business_requirement_deliverable/models/project.py b/business_requirement_deliverable/models/project.py index 8d55eb2c83..4b34917c31 100644 --- a/business_requirement_deliverable/models/project.py +++ b/business_requirement_deliverable/models/project.py @@ -15,10 +15,3 @@ class Project(models.Model): Deliverables linked to this project. Currency of the Deliverables will be the one from this pricelist.''' ) - - @api.multi - def get_closest_ancestor_pricelist(self): - for project in self: - pricelist = self.env['product.pricelist'].browse( - project.pricelist_id.id) - return pricelist diff --git a/business_requirement_deliverable/views/business_view.xml b/business_requirement_deliverable/views/business_view.xml index 297a86ba11..4363da13bb 100644 --- a/business_requirement_deliverable/views/business_view.xml +++ b/business_requirement_deliverable/views/business_view.xml @@ -9,7 +9,7 @@ - + @@ -70,6 +70,7 @@ +