Skip to content

Commit

Permalink
[FIX] business_requirement_deliverable_cost
Browse files Browse the repository at this point in the history
Fix comments by simplify and choose the right tools to select the information
needed for product pricelist calculation.
	modified:   business_requirement_deliverable_cost/models/business.py
	modified:   business_requirement_deliverable_cost/tests/test_br.py
  • Loading branch information
Victor Martin committed Feb 17, 2017
1 parent e36b57f commit 6ebfc4b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 56 deletions.
49 changes: 20 additions & 29 deletions business_requirement_deliverable_cost/models/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class BusinessRequirementResource(models.Model):
'group_business_requirement_cost_control',
)

partner_id = fields.Many2one(
'res.partner',
related='business_requirement_deliverable_id.'
'business_requirement_id.partner_id',
string='Parter ID Related',
readonly=True,
)

@api.multi
@api.depends('unit_price', 'qty')
def _compute_get_price_total(self):
Expand All @@ -43,27 +51,12 @@ def _compute_sale_price_total(self):
for resource in self:
resource.sale_price_total = resource.sale_price_unit * resource.qty

@api.multi
def _get_partner(self):
self.ensure_one()
br_id = br_deliverable = False
if self.business_requirement_deliverable_id.id:
br_deliverable = self.business_requirement_deliverable_id
if self.business_requirement_deliverable_id.\
business_requirement_id.partner_id:
br_id = br_deliverable.business_requirement_id
if br_id and br_id.partner_id:
return br_id.partner_id
else:
return False

@api.multi
def _get_pricelist(self):
self.ensure_one()
partner_id = self._get_partner()
if partner_id:
if partner_id.property_product_pricelist:
return partner_id.property_product_pricelist
if self.partner_id:
if self.partner_id.property_product_pricelist:
return self.partner_id.property_product_pricelist
else:
return False

Expand All @@ -73,12 +66,11 @@ def product_id_change(self):
super(BusinessRequirementResource, self).product_id_change()
unit_price = self.product_id.standard_price
pricelist_id = self._get_pricelist()
partner_id = self._get_partner()
sale_price_unit = self.product_id.list_price
if pricelist_id and partner_id and self.uom_id:
if pricelist_id and self.partner_id and self.uom_id:
product = self.product_id.with_context(
lang=partner_id.lang,
partner=partner_id.id,
lang=self.partner_id.lang,
partner=self.partner_id.id,
quantity=self.qty,
pricelist=pricelist_id.id,
uom=self.uom_id.id,
Expand All @@ -96,7 +88,6 @@ def product_uom_change(self):
unit_price = self.unit_price
sale_price_unit = self.product_id.list_price
pricelist = self._get_pricelist()
partner_id = self._get_partner()
product_uom = self.env['product.uom']

if self.qty != 0:
Expand All @@ -108,8 +99,8 @@ def product_uom_change(self):

if pricelist:
product = self.product_id.with_context(
lang=partner_id.lang,
partner=partner_id.id,
lang=self.partner_id.lang,
partner=self.partner_id.id,
quantity=self.qty,
pricelist=pricelist.id,
uom=self.uom_id.id,
Expand Down Expand Up @@ -139,12 +130,12 @@ def action_button_update_estimation(self):
if deliverable.resource_ids:
for resource in deliverable.resource_ids:
pricelist_id = resource._get_pricelist()
partner_id = resource._get_partner()
resource.sale_price_unit = resource.product_id.lst_price
if pricelist_id and partner_id and resource.uom_id:
if pricelist_id and resource.partner_id \
and resource.uom_id:
product = resource.product_id.with_context(
lang=partner_id.lang,
partner=partner_id.id,
lang=resource.partner_id.lang,
partner=resource.partner_id.id,
quantity=resource.qty,
pricelist=pricelist_id.id,
uom=resource.uom_id.id,
Expand Down
37 changes: 10 additions & 27 deletions business_requirement_deliverable_cost/tests/test_br.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ def test_product_id_change(self):
unit_price = 0
unit_price = resource.product_id.standard_price
pricelist_id = resource._get_pricelist()
partner_id = resource._get_partner()
# partner_id = resource._get_partner()
sale_price_unit = resource.product_id.list_price
if pricelist_id and partner_id and resource.uom_id:
if pricelist_id and resource.partner_id and resource.uom_id:
product = resource.product_id.with_context(
lang=partner_id.lang,
partner=partner_id.id,
lang=resource.partner_id.lang,
# partner=resource.partner_id.id,
quantity=resource.qty,
pricelist=pricelist_id.id,
uom=resource.uom_id.id,
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_product_uom_change(self):
unit_price = resource.unit_price
sale_price_unit = resource.product_id.list_price
pricelist = resource._get_pricelist()
partner_id = resource._get_partner()
# partner_id = resource._get_partner()
product_uom = resource.env['product.uom']

if resource.qty != 0:
Expand All @@ -195,8 +195,8 @@ def test_product_uom_change(self):

if pricelist:
product = resource.product_id.with_context(
lang=partner_id.lang,
partner=partner_id.id,
lang=resource.partner_id.lang,
partner=resource.partner_id.id,
quantity=resource.qty,
pricelist=pricelist.id,
uom=resource.uom_id.id,
Expand All @@ -218,12 +218,11 @@ def test_action_button_update_estimation(self):
if deliverable.resource_ids:
for resource in deliverable.resource_ids:
pricelist_id = resource._get_pricelist()
partner_id = resource._get_partner()
sale_price_unit = resource.product_id.lst_price
if pricelist_id and partner_id and resource.uom_id:
if pricelist_id and resource.partner_id and resource.uom_id:
product = resource.product_id.with_context(
lang=partner_id.lang,
partner=partner_id.id,
lang=resource.partner_id.lang,
partner=resource.partner_id.id,
quantity=resource.qty,
pricelist=pricelist_id.id,
uom=resource.uom_id.id,
Expand All @@ -232,19 +231,3 @@ def test_action_button_update_estimation(self):

self.assertEqual(
resource.sale_price_unit, sale_price_unit)

def test_get_partner(self):
resource = self.env['business.requirement.resource'].search([
('name', '=', 'Resource Line1')])
self.assertEqual(
resource.business_requirement_deliverable_id.
business_requirement_id.partner_id,
resource._get_partner()
)
resource.business_requirement_deliverable_id.\
business_requirement_id.partner_id = None
self.assertEqual(
resource.business_requirement_deliverable_id.
business_requirement_id.partner_id.id,
resource._get_partner()
)

0 comments on commit 6ebfc4b

Please sign in to comment.