Skip to content

Commit

Permalink
Merge pull request #53 from gurneyalex/8.0-fix_cost_estimate_consignee
Browse files Browse the repository at this point in the history
fix: bug when creating CE from LR
  • Loading branch information
lepistone committed Nov 25, 2014
2 parents 92ca944 + bfa03aa commit 5a5f859
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 4 deletions.
2 changes: 1 addition & 1 deletion logistic_budget/tests/test_propagate_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def setUp(self):
procurement_method='other',
proposed_product_id=self.env['product.product'],
)
self.source.requisition_line_id.requisition_id.consignee_id.id = \
self.source.requisition_line_id.requisition_id.partner_id.id = \
partner1_id
self.request = self.env['logistic.requisition'].new({
'budget_holder_id': 1,
Expand Down
19 changes: 18 additions & 1 deletion logistic_order/model/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api
from openerp import models, fields, api, exceptions
from openerp.tools.translate import _


class SaleOrder(models.Model):
Expand Down Expand Up @@ -56,6 +57,22 @@ class SaleOrder(models.Model):
section_id = fields.Many2one(states=LO_STATES)
procurement_group_id = fields.Many2one(states=LO_STATES)

# redefine consignee_id with required=False
# we have a constraint to make it
# required only if cost_estimate_only is False
consignee_id = fields.Many2one(
'res.partner',
string='Consignee',
required=False,
help="The person to whom the shipment is to be delivered.")

@api.one
@api.constrains('cost_estimate_only', 'consignee_id')
def _check_consignee(self):
if not self.cost_estimate_only and not self.consignee_id:
raise exceptions.Warning(_('If this is not only for Cost Estimate,'
' you must provide a Consignee'))

@api.multi
def action_quotation_send(self):
""" In case of Cost Estimate only, register an option to set the
Expand Down
1 change: 1 addition & 0 deletions logistic_requisition/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
],
"test": ['test/line_assigned.yml',
'test/requisition_create_cost_estimate.yml',
'test/requisition_create_cost_estimate_only.yml',
'test/requisition_sourcing_with_tender.yml',
'test/requisition_cancel_reason.yml',
'test/logistic_requisition_report_test.yml',
Expand Down
123 changes: 123 additions & 0 deletions logistic_requisition/test/requisition_create_cost_estimate_only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
-
Given I create a logistic requisition for cost estimate only, without setting a consignee
-
!record {model: logistic.requisition, id: logistic_requisition_cost_estimate_only_01}:
partner_id: base.res_partner_4
cost_estimate_only: True
date: !eval "time.strftime('%Y-%m-%d')"
date_delivery: !eval "time.strftime('%Y-%m-%d')"
user_id: base.user_demo
incoterm_id: stock.incoterm_FCA
incoterm_address: incoterm address as text
analytic_id: account.analytic_consultancy
pricelist_id: product.list0
-
And I add a line 1
-
!record {model: logistic.requisition.line, id: logistic_requisition_line_cost_estimate_only_01}:
requisition_id: logistic_requisition_cost_estimate_only_01
product_id: product.product_product_32
description: "[HEAD] Headset standard"
requested_qty: 100
requested_uom_id: product.product_uom_unit
date_delivery: !eval "time.strftime('%Y-%m-%d')"
logistic_user_id: base.user_demo
-
And I add a source line to the line 1
-
!record {model: logistic.requisition.source, id: logistic_requisition_source_cost_estimate_only_01}:
requisition_line_id: logistic_requisition_line_cost_estimate_only_01
proposed_qty: 110
proposed_product_id: product.product_product_32
proposed_uom_id: product.product_uom_unit
unit_cost: 8
procurement_method: wh_dispatch
price_is: fixed
dispatch_location_id: stock.stock_location_components
-
When I confirm the logistic requisition
-
!python {model: logistic.requisition, id: logistic_requisition_cost_estimate_only_01}: |
self.button_confirm()
-
And I source the lines
-
!python {model: logistic.requisition.line}: |
line1_id = ref("logistic_requisition_line_cost_estimate_only_01")
ids = [line1_id, ]
self.button_sourced(cr, uid, ids)
-
I open the wizard to create a cost estimate from the logistic requisition
-
!python {model: logistic.requisition.cost.estimate}: |
context = {'active_model': 'logistic.requisition',
'active_ids': [ref('logistic_requisition_cost_estimate_only_01')],
}
wizard_id = self.create(cr, uid, {}, context=context)
open_action = self.cost_estimate(cr, uid, wizard_id)
cost_estimate_id = open_action['res_id']
cost_estimate_obj = self.pool.get('sale.order')
cost_estimate = cost_estimate_obj.browse(cr, uid, cost_estimate_id)
assert len(cost_estimate.order_line) == 1, (
"Cost Estimate should have 1 line, 1 per logistic requisition line")
-
I check if the information of the logistic requisition are propagated correctly
-
!python {model: logistic.requisition, id: logistic_requisition_cost_estimate_only_01}: |
sale_obj = self.env['sale.order']
sale = sale_obj.search([('requisition_id', '=', self.id)])
sale.ensure_one()
assert sale.partner_id == self.partner_id
assert sale.partner_invoice_id == self.partner_id
assert sale.consignee_id == self.consignee_id
assert sale.incoterm == self.incoterm_id
assert sale.incoterm_address == self.incoterm_address
assert sale.project_id == self.analytic_id
-
I check if the information of the lines is correct
-
!python {model: logistic.requisition.source}: |
def check_line(self, cr, uid, source_line_id):
# the upper scope is not accessible here,
# that's why self, cr, uid are passed as arguments
location_obj = self.pool['stock.location']
source = self.browse(cr, uid, source_line_id)
sale_lines = source.requisition_id.line_ids[0].cost_estimate_id.order_line
sale_line = [line for line in sale_lines if line.product_id == source.proposed_product_id][0]
line = source.requisition_line_id
assert sale_line.product_id == source.proposed_product_id, (
"product_id should be %s, received %s" %
(source.proposed_product_id, sale_line.product_id))

assert sale_line.name == line.description, (
"name should be %s, received %s" %
(line.description, sale_line.name))

assert sale_line.product_uom_qty == source.proposed_qty, (
"qty should be %s, received %s" %
(source.proposed_qty, sale_line.product_uom_qty))

assert sale_line.product_uom == source.proposed_uom_id, (
"unit of measure should be %s, received %s" %
(source.proposed_uom_id, sale_line.product_uom))

assert sale_line.price_unit == source.unit_cost, (
"price_unit should be %s, received %s" %
(source.unit_cost, sale_line.price_unit))

assert sale_line.price_is == source.price_is, (
"price_is should be %s, received %s" %
(source.price_is, sale_line.price_is))

loc = source.dispatch_location_id
if location_obj.get_warehouse(cr, uid, loc):
assert sale_line.warehouse_id.id == location_obj.get_warehouse(cr, uid, loc), (
"dispatch should be %s, received %s" %
(location_obj.get_warehouse(cr, uid, loc), sale_line.warehouse_id.id))
else:
assert not sale_line.warehouse_id, (
"No dispatch location on requisition line, but received a "
"location in sale order line")

source1_id = ref("logistic_requisition_source_cost_estimate_only_01")
check_line(self, cr, uid, source1_id)
8 changes: 7 additions & 1 deletion logistic_requisition/view/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
<record id="view_order_form" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="inherit_id" ref="logistic_consignee.view_order_form"/>
<field name="arch" type="xml">
<field name="consignee_id" position="before">
<field name='cost_estimate_only'/>
</field>
<field name="consignee_id" position="attributes">
<attribute name="attrs">{'required': [('cost_estimate_only', '!=', True)]}</attribute>
</field>
<xpath expr="//field[@name='order_line']/tree//field[@name='price_unit']"
position="after">
<field name="price_is"/>
Expand Down
3 changes: 2 additions & 1 deletion logistic_requisition/wizard/cost_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _prepare_cost_estimate_line(self, sourcing):
onchange_vals = sale_line_obj.product_id_change(
requisition.consignee_id.property_product_pricelist.id,
sourcing.proposed_product_id.id,
partner_id=requisition.consignee_id.id,
partner_id=requisition.partner_id.id,
qty=sourcing.proposed_qty,
uom=sourcing.proposed_uom_id.id).get('value', {})
# price_unit and type of the requisition line must be kept
Expand Down Expand Up @@ -211,6 +211,7 @@ def _prepare_cost_estimate(self, requisition,
'partner_invoice_id': partner_id,
'partner_shipping_id': requisition.consignee_shipping_id.id,
'consignee_id': requisition.consignee_id.id,
'cost_estimate_only': requisition.cost_estimate_only,
'order_line': [(0, 0, x) for x in estimate_lines],
'incoterm': requisition.incoterm_id.id,
'incoterm_address': requisition.incoterm_address,
Expand Down

0 comments on commit 5a5f859

Please sign in to comment.