2018-01-16 06:58:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-01-16 11:34:37 +01:00
|
|
|
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
2018-01-16 06:58:15 +01:00
|
|
|
|
2018-01-16 11:34:37 +01:00
|
|
|
from flectra import api, fields, models
|
2018-01-16 06:58:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class StockLocationRoute(models.Model):
|
|
|
|
_inherit = "stock.location.route"
|
|
|
|
sale_selectable = fields.Boolean("Selectable on Sales Order Line")
|
|
|
|
|
|
|
|
|
|
|
|
class StockMove(models.Model):
|
|
|
|
_inherit = "stock.move"
|
|
|
|
sale_line_id = fields.Many2one('sale.order.line', 'Sale Line')
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _prepare_merge_moves_distinct_fields(self):
|
|
|
|
distinct_fields = super(StockMove, self)._prepare_merge_moves_distinct_fields()
|
|
|
|
distinct_fields.append('sale_line_id')
|
|
|
|
return distinct_fields
|
|
|
|
|
|
|
|
@api.model
|
|
|
|
def _prepare_merge_move_sort_method(self, move):
|
|
|
|
move.ensure_one()
|
|
|
|
keys_sorted = super(StockMove, self)._prepare_merge_move_sort_method(move)
|
|
|
|
keys_sorted.append(move.sale_line_id.id)
|
|
|
|
return keys_sorted
|
|
|
|
|
|
|
|
def _action_done(self):
|
|
|
|
result = super(StockMove, self)._action_done()
|
2018-07-09 12:23:28 +02:00
|
|
|
for line in result.mapped('sale_line_id').sudo():
|
2018-01-16 06:58:15 +01:00
|
|
|
line.qty_delivered = line._get_delivered_qty()
|
|
|
|
return result
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def write(self, vals):
|
|
|
|
res = super(StockMove, self).write(vals)
|
|
|
|
if 'product_uom_qty' in vals:
|
|
|
|
for move in self:
|
|
|
|
if move.state == 'done':
|
|
|
|
sale_order_lines = self.filtered(lambda move: move.sale_line_id and move.product_id.expense_policy == 'no').mapped('sale_line_id')
|
2018-07-09 12:23:28 +02:00
|
|
|
for line in sale_order_lines.sudo():
|
2018-01-16 06:58:15 +01:00
|
|
|
line.qty_delivered = line._get_delivered_qty()
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
class ProcurementGroup(models.Model):
|
|
|
|
_inherit = 'procurement.group'
|
|
|
|
|
|
|
|
sale_id = fields.Many2one('sale.order', 'Sale Order')
|
|
|
|
|
|
|
|
|
|
|
|
class ProcurementRule(models.Model):
|
|
|
|
_inherit = 'procurement.rule'
|
|
|
|
|
|
|
|
def _get_stock_move_values(self, product_id, product_qty, product_uom, location_id, name, origin, values, group_id):
|
|
|
|
result = super(ProcurementRule, self)._get_stock_move_values(product_id, product_qty, product_uom, location_id, name, origin, values, group_id)
|
|
|
|
if values.get('sale_line_id', False):
|
|
|
|
result['sale_line_id'] = values['sale_line_id']
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
class StockPicking(models.Model):
|
|
|
|
_inherit = 'stock.picking'
|
|
|
|
|
|
|
|
sale_id = fields.Many2one(related="group_id.sale_id", string="Sales Order", store=True)
|