diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py index 3b3530cd8e2..45097bb1a9d 100644 --- a/addons/mrp/stock.py +++ b/addons/mrp/stock.py @@ -240,6 +240,13 @@ class stock_warehouse(osv.osv): all_routes += [warehouse.manufacture_pull_id.route_id.id] return all_routes + def _handle_renaming(self, cr, uid, warehouse, name, context=None): + res = super(stock_warehouse, self)._handle_renaming(cr, uid, warehouse, name, context=context) + pull_obj = self.pool.get('procurement.rule') + #change the manufacture pull rule name + pull_obj.write(cr, uid, warehouse.manufacture_pull_id.id, {'name': warehouse.manufacture_pull_id.name.replace(warehouse.name, name, 1)}, context=context) + return res + def _get_all_products_to_resupply(self, cr, uid, warehouse, context=None): res = super(stock_warehouse, self)._get_all_products_to_resupply(cr, uid, warehouse, context=context) if warehouse.manufacture_pull_id and warehouse.manufacture_pull_id.route_id: diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 142f13997c4..d37e826fdeb 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -662,7 +662,8 @@ class purchase_order(osv.osv): if order_line.product_uom.id != order_line.product_id.uom_id.id: price_unit *= order_line.product_uom.factor if order.currency_id.id != order.company_id.currency_id.id: - price_unit = self.pool.get('res.currency').compute(cr, uid, order.currency_id.id, order.company_id.currency_id.id, price_unit, context=context) + #we don't round the price_unit, as we may want to store the standard price with more digits than allowed by the currency + price_unit = self.pool.get('res.currency').compute(cr, uid, order.currency_id.id, order.company_id.currency_id.id, price_unit, round=False, context=context) return { 'name': order_line.name or '', diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py index 42b9969acab..06b484ec149 100644 --- a/addons/purchase/stock.py +++ b/addons/purchase/stock.py @@ -148,6 +148,13 @@ class stock_warehouse(osv.osv): break return res + def _handle_renaming(self, cr, uid, warehouse, name, context=None): + res = super(stock_warehouse, self)._handle_renaming(cr, uid, warehouse, name, context=context) + pull_obj = self.pool.get('procurement.rule') + #change the buy pull rule name + pull_obj.write(cr, uid, warehouse.buy_pull_id.id, {'name': warehouse.buy_pull_id.name.replace(warehouse.name, name, 1)}, context=context) + return res + def change_route(self, cr, uid, ids, warehouse, new_reception_step=False, new_delivery_step=False, context=None): res = super(stock_warehouse, self).change_route(cr, uid, ids, warehouse, new_reception_step=new_reception_step, new_delivery_step=new_delivery_step, context=context) if warehouse.in_type_id.default_location_dest_id != warehouse.buy_pull_id.location_id: diff --git a/addons/purchase_requisition/purchase_requisition.py b/addons/purchase_requisition/purchase_requisition.py index afb18dc0d2c..3336823247a 100644 --- a/addons/purchase_requisition/purchase_requisition.py +++ b/addons/purchase_requisition/purchase_requisition.py @@ -119,15 +119,12 @@ class purchase_requisition(osv.osv): context = {} res = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid, 'purchase_requisition', 'purchase_line_tree', context=context) res['context'] = context - po_ids_browse = self.browse(cr, uid, ids, context=context)[0].po_line_ids - po_ids = [] - for po in po_ids_browse: - po_ids.append(po.id) - res['context'].update({ + po_lines = self.browse(cr, uid, ids, context=context)[0].po_line_ids + res['context'] = { 'search_default_groupby_product': True, 'search_default_hide_cancelled': True, - }) - res['domain'] = [('id', 'in', po_ids)] + } + res['domain'] = [('id', 'in', [line.id for line in po_lines])] return res def open_rfq(self, cr, uid, ids, context=None): @@ -212,6 +209,27 @@ class purchase_requisition(osv.osv): return False return True + def _prepare_po_from_tender(self, cr, uid, tender, context=None): + """ Prepare the values to write in the purchase order + created from a tender. + + :param tender: the source tender from which we generate a purchase order + """ + return {'order_line': [], + 'requisition_id': tender.id, + 'origin': tender.name} + + def _prepare_po_line_from_tender(self, cr, uid, tender, line, purchase_id, context=None): + """ Prepare the values to write in the purchase order line + created from a line of the tender. + + :param tender: the source tender from which we generate a purchase order + :param line: the source tender's line from which we generate a line + :param purchase_id: the id of the new purchase + """ + return {'product_qty': line.quantity_bid, + 'order_id': purchase_id} + def generate_po(self, cr, uid, ids, context=None): """ Generate all purchase order based on selected lines, should only be called on one tender at a time @@ -255,10 +273,12 @@ class purchase_requisition(osv.osv): for supplier, product_line in id_per_supplier.items(): #copy a quotation for this supplier and change order_line then validate it quotation_id = po.search(cr, uid, [('requisition_id', '=', tender.id), ('partner_id', '=', supplier)], limit=1)[0] - new_po = po.copy(cr, uid, quotation_id, default={'order_line': [], 'requisition_id': tender.id, 'origin': tender.name}, context=ctx) + vals = self._prepare_po_from_tender(cr, uid, tender, context=context) + new_po = po.copy(cr, uid, quotation_id, default=vals, context=ctx) #duplicate po_line and change product_qty if needed and associate them to newly created PO for line in product_line: - poline.copy(cr, uid, line.id, default={'product_qty': line.quantity_bid, 'order_id': new_po}, context=context) + vals = self._prepare_po_line_from_tender(cr, uid, tender, line, new_po, context=context) + poline.copy(cr, uid, line.id, default=vals, context=context) #use workflow to set new PO state to confirm po.signal_purchase_confirm(cr, uid, [new_po]) diff --git a/addons/stock/res_config_view.xml b/addons/stock/res_config_view.xml index befc46c1cf4..2ce88479c9a 100644 --- a/addons/stock/res_config_view.xml +++ b/addons/stock/res_config_view.xml @@ -70,12 +70,6 @@