Skip to content

Commit

Permalink
[FIX] purchase: sections and notes.
Browse files Browse the repository at this point in the history
#34737 didn't go in enough depth to
ensure sections and notes don't break purchase flows.

closes #39474

X-original-commit: 1e8ea4f
Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
  • Loading branch information
Feyensv authored and fw-bot committed Oct 28, 2019
1 parent 198f0df commit 7720bb2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions addons/purchase/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def _compute_qty_invoiced(self):
@api.depends('product_id')
def _compute_qty_received_method(self):
for line in self:
if line.product_id.type in ['consu', 'service']:
if line.product_id and line.product_id.type in ['consu', 'service']:
line.qty_received_method = 'manual'
else:
line.qty_received_method = False
Expand Down Expand Up @@ -697,7 +697,7 @@ def _onchange_quantity(self):
@api.depends('product_uom', 'product_qty', 'product_id.uom_id')
def _compute_product_uom_qty(self):
for line in self:
if line.product_id.uom_id != line.product_uom:
if line.product_id and line.product_id.uom_id != line.product_uom:
line.product_uom_qty = line.product_uom._compute_quantity(line.product_qty, line.product_id.uom_id)
else:
line.product_uom_qty = line.product_qty
Expand Down
8 changes: 4 additions & 4 deletions addons/purchase_stock/models/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class PurchaseOrderLine(models.Model):

def _compute_qty_received_method(self):
super(PurchaseOrderLine, self)._compute_qty_received_method()
for line in self:
for line in self.filtered(lambda l: not l.display_type):
if line.product_id.type in ['consu', 'product']:
line.qty_received_method = 'stock_moves'

Expand Down Expand Up @@ -275,7 +275,7 @@ def create(self, values):
return line

def write(self, values):
for line in self:
for line in self.filtered(lambda l: not l.display_type):
if values.get('date_planned') and line.propagate_date:
new_date = fields.Datetime.to_datetime(values['date_planned'])
delta_days = (new_date - line.date_planned).total_seconds() / 86400
Expand All @@ -297,7 +297,7 @@ def write(self, values):

def _create_or_update_picking(self):
for line in self:
if line.product_id.type in ('product', 'consu'):
if line.product_id and line.product_id.type in ('product', 'consu'):
# Prevent decreasing below received quantity
if float_compare(line.product_qty, line.qty_received, line.product_uom.rounding) < 0:
raise UserError(_('You cannot decrease the ordered quantity below the received quantity.\n'
Expand Down Expand Up @@ -394,7 +394,7 @@ def _prepare_stock_moves(self, picking):

def _create_stock_moves(self, picking):
values = []
for line in self:
for line in self.filtered(lambda l: not l.display_type):
for val in line._prepare_stock_moves(picking):
values.append(val)
return self.env['stock.move'].create(values)
Expand Down
2 changes: 1 addition & 1 deletion addons/purchase_stock/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _run_buy(self, procurements):
procurements = self._merge_procurements(procurements_to_merge)

po_lines_by_product = {}
grouped_po_lines = groupby(po.order_line.filtered(lambda l: l.product_uom == l.product_id.uom_po_id).sorted('product_id'), key=lambda l: l.product_id.id)
grouped_po_lines = groupby(po.order_line.filtered(lambda l: not l.display_type and l.product_uom == l.product_id.uom_po_id).sorted('product_id'), key=lambda l: l.product_id.id)
for product, po_lines in grouped_po_lines:
po_lines_by_product[product] = self.env['purchase.order.line'].concat(*list(po_lines))
po_line_values = []
Expand Down

0 comments on commit 7720bb2

Please sign in to comment.