[IMP] Use group propagation options from procurement rule
This commit is contained in:
+20
-15
@@ -46,9 +46,11 @@ class purchase_order(osv.osv):
|
||||
val = val1 = 0.0
|
||||
cur = order.pricelist_id.currency_id
|
||||
for line in order.order_line:
|
||||
val1 += line.price_subtotal
|
||||
for c in self.pool.get('account.tax').compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, line.product_id, order.partner_id)['taxes']:
|
||||
val += c.get('amount', 0.0)
|
||||
taxes = self.pool.get('account.tax').compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, line.product_id, order.partner_id)
|
||||
val1 += cur_obj.round(cr, uid, cur, taxes['total']) #Decimal precision?
|
||||
for c in taxes['taxes']:
|
||||
val += c.get('amount', 0.0)
|
||||
|
||||
res[order.id]['amount_tax']=cur_obj.round(cr, uid, cur, val)
|
||||
res[order.id]['amount_untaxed']=cur_obj.round(cr, uid, cur, val1)
|
||||
res[order.id]['amount_total']=res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
|
||||
@@ -266,7 +268,7 @@ class purchase_order(osv.osv):
|
||||
"Based on generated invoice: create a draft invoice you can validate later.\n" \
|
||||
"Based on incoming shipments: let you create an invoice when receipts are validated."
|
||||
),
|
||||
'minimum_planned_date':fields.function(_minimum_planned_date, fnct_inv=_set_minimum_planned_date, string='Expected Date', type='date', select=True, help="This is computed as the minimum scheduled date of all purchase order lines' products.",
|
||||
'minimum_planned_date':fields.function(_minimum_planned_date, fnct_inv=_set_minimum_planned_date, string='Expected Date', type='datetime', select=True, help="This is computed as the minimum scheduled date of all purchase order lines' products.",
|
||||
store = {
|
||||
'purchase.order.line': (_get_order, ['date_planned'], 10),
|
||||
}
|
||||
@@ -296,7 +298,8 @@ class purchase_order(osv.osv):
|
||||
states={'confirmed': [('readonly', True)], 'approved': [('readonly', True)], 'done': [('readonly', True)]}),
|
||||
'related_location_id': fields.related('picking_type_id', 'default_location_dest_id', type='many2one', relation='stock.location', string="Related location", store=True),
|
||||
'shipment_count': fields.function(_count_all, type='integer', string='Incoming Shipments', multi=True),
|
||||
'invoice_count': fields.function(_count_all, type='integer', string='Invoices', multi=True)
|
||||
'invoice_count': fields.function(_count_all, type='integer', string='Invoices', multi=True),
|
||||
'group_id': fields.many2one('procurement.group', string="Procurement Group"),
|
||||
}
|
||||
_defaults = {
|
||||
'date_order': fields.datetime.now,
|
||||
@@ -720,7 +723,7 @@ class purchase_order(osv.osv):
|
||||
'product_uom': order_line.product_uom.id,
|
||||
'product_uos': order_line.product_uom.id,
|
||||
'date': order.date_order,
|
||||
'date_expected': fields.date.date_to_datetime(self, cr, uid, order_line.date_planned, context),
|
||||
'date_expected': order_line.date_planned,
|
||||
'location_id': order.partner_id.property_stock_supplier.id,
|
||||
'location_dest_id': order.location_id.id,
|
||||
'picking_id': picking_id,
|
||||
@@ -747,7 +750,6 @@ class purchase_order(osv.osv):
|
||||
'product_uom_qty': min(procurement_qty, diff_quantity),
|
||||
'product_uos_qty': min(procurement_qty, diff_quantity),
|
||||
'move_dest_id': procurement.move_dest_id.id, #move destination is same as procurement destination
|
||||
'group_id': procurement.group_id.id or group_id, #move group is same as group of procurements if it exists, otherwise take another group
|
||||
'procurement_id': procurement.id,
|
||||
'invoice_state': procurement.rule_id.invoice_state or (procurement.location_id and procurement.location_id.usage == 'customer' and procurement.invoice_state=='picking' and '2binvoiced') or (order.invoice_method == 'picking' and '2binvoiced') or 'none', #dropship case takes from sale
|
||||
'propagate': procurement.rule_id.propagate,
|
||||
@@ -783,7 +785,10 @@ class purchase_order(osv.osv):
|
||||
"""
|
||||
stock_move = self.pool.get('stock.move')
|
||||
todo_moves = []
|
||||
new_group = self.pool.get("procurement.group").create(cr, uid, {'name': order.name, 'partner_id': order.partner_id.id}, context=context)
|
||||
if order.group_id:
|
||||
new_group = order.group_id.id
|
||||
else:
|
||||
new_group = self.pool.get("procurement.group").create(cr, uid, {'name': order.name, 'partner_id': order.partner_id.id}, context=context)
|
||||
|
||||
for order_line in order_lines:
|
||||
if not order_line.product_id:
|
||||
@@ -1380,7 +1385,7 @@ class procurement_order(osv.osv):
|
||||
# Regroup POs
|
||||
cr.execute("""
|
||||
SELECT psi.name, p.id, pr.id, pr.picking_type_id, p.location_id, p.partner_dest_id, p.company_id, p.group_id,
|
||||
pg.propagate_to_purchase, psi.qty
|
||||
pr.group_propagation_option, pr.group_id, psi.qty
|
||||
FROM procurement_order AS p
|
||||
LEFT JOIN procurement_rule AS pr ON pr.id = p.rule_id
|
||||
LEFT JOIN procurement_group AS pg ON p.group_id = pg.id,
|
||||
@@ -1397,18 +1402,19 @@ class procurement_order(osv.osv):
|
||||
create_purchase_procs = {} # Lines to add to a newly to create po
|
||||
add_purchase_procs = {} # Lines to add/adjust in an existing po
|
||||
proc_seller = {} # To check we only process one po
|
||||
for partner, proc, rule, pick_type, location, partner_dest, company, group, propagate_to_purchase, qty in res:
|
||||
for partner, proc, rule, pick_type, location, partner_dest, company, group, group_propagation, fixed_group, qty in res:
|
||||
if not proc_seller.get(proc):
|
||||
proc_seller[proc] = partner
|
||||
new = partner, rule, pick_type, location, company, group, propagate_to_purchase
|
||||
new = partner, rule, pick_type, location, company, group, group_propagation, fixed_group
|
||||
if new != old:
|
||||
old = new
|
||||
available_draft_po = False
|
||||
dom = [
|
||||
('partner_id', '=', partner), ('state', '=', 'draft'), ('picking_type_id', '=', pick_type),
|
||||
('location_id', '=', location), ('company_id', '=', company), ('dest_address_id', '=', partner_dest)]
|
||||
if group and propagate_to_purchase:
|
||||
if group_propagation == 'propagate':
|
||||
dom += [('group_id', '=', group)]
|
||||
elif group_propagation == 'fixed':
|
||||
dom += [('group_id', '=', fixed_group)]
|
||||
available_draft_po_ids = po_obj.search(cr, uid, dom, context=context)
|
||||
available_draft_po = available_draft_po_ids and available_draft_po_ids[0] or False
|
||||
# Add to dictionary
|
||||
@@ -1469,7 +1475,6 @@ class procurement_order(osv.osv):
|
||||
procs += [proc]
|
||||
line_values += [(1, line.id, {'product_qty': line.product_qty + tot_qty, 'procurement_ids': [(4, x[0]) for x in lines_to_update[line]]})]
|
||||
if procs:
|
||||
print procs
|
||||
self.message_post(cr, uid, procs, body=_("Quantity added in existing Purchase Order Line"), context=context)
|
||||
|
||||
# Create lines for which no line exists yet
|
||||
@@ -1502,7 +1507,7 @@ class procurement_order(osv.osv):
|
||||
line_values += [(0, 0, value_lines[x]) for x in value_lines.keys()]
|
||||
name = seq_obj.get(cr, uid, 'purchase.order') or _('PO: %s') % procurement.name
|
||||
gpo = procurement.rule_id.group_propagation_option
|
||||
group = (gpo == 'fixed' and procurement.rule_id.group_id.id) or (gpo=='propagate' and procurement.group_id.id) or False,
|
||||
group = (gpo == 'fixed' and procurement.rule_id.group_id.id) or (gpo == 'propagate' and procurement.group_id.id) or False
|
||||
po_vals = {
|
||||
'name': name,
|
||||
'origin': procurement.origin,
|
||||
|
||||
Reference in New Issue
Block a user