Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] get resource sale unit price from pricelist when get from default #43

Open
wants to merge 5 commits into
base: business_requirement_deliverable_8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
32 changes: 17 additions & 15 deletions business_requirement_deliverable/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,22 @@ 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
unit_price = product.list_price
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 \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be br.get_estimation_pricelist()

br.partner_id and self.uom_id:
pricelist = br.project_id.get_closest_ancestor_pricelist()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move before the if to use in the condition and use br.get_estimation_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
Expand All @@ -204,14 +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 and br.partner_id:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

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,
)
self.unit_price = product.price
Expand All @@ -238,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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be br.get_estimation_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:
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
9 changes: 8 additions & 1 deletion business_requirement_deliverable/models/project.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -15,3 +15,10 @@ 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure this is enough.
Rule should be for the pricelist:
If pricelist in master project then use project.pricelist
else if pricelist is project parent then use parent_project.pricelist
else use partner.pricelist

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elicoidal Seb told me that the rule had not been confirmed, So just let me keep the function and in other model can use this function.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seb-elico your input ?

return pricelist
8 changes: 6 additions & 2 deletions business_requirement_deliverable_cost/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ def product_id_change(self):
resource.business_requirement_deliverable_id.project_id
if deliverable_project.pricelist_id and \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong. It should use get_estimation_pricelist (of the BR)

deliverable_project.partner_id and resource.uom_id:
pricelist = \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this before the if to use it in the condition. It should use get_estimation_pricelist (of the BR)

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
Expand All @@ -63,11 +65,13 @@ def product_uom_change(self):
resource.business_requirement_deliverable_id.project_id
if deliverable_project.pricelist_id and \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problems here

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be self.get_estimation_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
Expand Down