Skip to content

Commit

Permalink
Merge PR #786 into 11.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Nov 6, 2019
2 parents a39fab5 + 359f345 commit c51574d
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def _prepare_wizard_line(self, vals, order_line=False):
qty_to_order = abs(
min(0, units_virtual_available - vals.get('qty_delivered', 0)))
vals['is_modified'] = bool(qty_to_order)
units_included = order_line and order_line.product_qty or qty_to_order
price_unit = product_id._select_seller(
partner_id=self.order_id.partner_id,
date=fields.Date.today(),
quantity=units_included,
uom_id=product_id.uom_po_id,
).price
return {
'purchase_line_id': order_line and order_line.id,
'product_id': product_id.id,
Expand All @@ -148,8 +155,8 @@ def _prepare_wizard_line(self, vals, order_line=False):
'units_avg_delivered': (vals.get('qty_delivered', 0) /
self._get_total_days()),
'units_delivered': vals.get('qty_delivered', 0),
'units_included': (order_line and order_line.product_qty or
qty_to_order),
'units_included': units_included,
'price_unit': price_unit,
'is_modified': vals.get('is_modified', False),
}

Expand Down Expand Up @@ -246,7 +253,7 @@ class PurchaseOrderRecommendationLine(models.TransientModel):
string='Product',
)
price_unit = fields.Monetary(
compute='_compute_price_unit',
readonly=True,
)
times_delivered = fields.Integer(
readonly=True,
Expand Down Expand Up @@ -283,20 +290,15 @@ class PurchaseOrderRecommendationLine(models.TransientModel):
)
is_modified = fields.Boolean()

@api.multi
@api.depends('partner_id', 'product_id', 'units_included')
def _compute_price_unit(self):
for one in self:
one.price_unit = one.product_id._select_seller(
partner_id=one.partner_id,
date=fields.Date.today(),
quantity=one.units_included,
uom_id=one.product_id.uom_po_id,
).price

@api.onchange('units_included')
def _onchange_units_included(self):
self.is_modified = bool(self.purchase_line_id or self.units_included)
self.price_unit = self.product_id._select_seller(
partner_id=self.partner_id,
date=fields.Date.today(),
quantity=self.units_included,
uom_id=self.product_id.uom_po_id,
).price

@api.multi
def _prepare_update_po_line(self):
Expand Down

0 comments on commit c51574d

Please sign in to comment.