mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
refactor
This commit is contained in:
@@ -26,9 +26,17 @@
|
||||
'wizards/mrp_inventory_procure_view.xml',
|
||||
'views/mrp_inventory_view.xml',
|
||||
'wizards/multi_level_mrp_view.xml',
|
||||
'wizards/mrp_move_create_po_view.xml',
|
||||
'views/mrp_menuitem.xml',
|
||||
'data/multi_level_mrp_cron.xml',
|
||||
'data/mrp_area_data.xml',
|
||||
],
|
||||
'demo': [
|
||||
'demo/product_category_demo.xml',
|
||||
'demo/product_product_demo.xml',
|
||||
'demo/res_partner_demo.xml',
|
||||
'demo/product_supplierinfo_demo.xml',
|
||||
'demo/mrp_bom_demo.xml',
|
||||
'demo/initial_on_hand_demo.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
|
||||
8
multi_level_mrp/data/mrp_area_data.xml
Normal file
8
multi_level_mrp/data/mrp_area_data.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
<record id="mrp_area_stock_wh0" model="mrp.area">
|
||||
<field name="name">WH/Stock</field>
|
||||
<field name="warehouse_id" ref="stock.warehouse0"/>
|
||||
<field name="location_id" ref="stock.stock_location_stock"/>
|
||||
</record>
|
||||
</odoo>
|
||||
32
multi_level_mrp/demo/initial_on_hand_demo.xml
Normal file
32
multi_level_mrp/demo/initial_on_hand_demo.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="stock_inventory_mrp_example" model="stock.inventory">
|
||||
<field name="name">Simulating MRP</field>
|
||||
</record>
|
||||
<record id="stock_inventory_line_1" model="stock.inventory.line">
|
||||
<field name="product_id" ref="product_product_pp_1"/>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="inventory_id" ref="stock_inventory_mrp_example"/>
|
||||
<field name="product_qty">10</field>
|
||||
<field name="location_id" ref="stock.stock_location_stock"/>
|
||||
</record>
|
||||
<record id="stock_inventory_line_2" model="stock.inventory.line">
|
||||
<field name="product_id" ref="product_product_pp_2"/>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="inventory_id" ref="stock_inventory_mrp_example"/>
|
||||
<field name="product_qty">20</field>
|
||||
<field name="location_id" ref="stock.stock_location_stock"/>
|
||||
</record>
|
||||
<record id="stock_inventory_line_3" model="stock.inventory.line">
|
||||
<field name="product_id" ref="product_product_sf_2"/>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="inventory_id" ref="stock_inventory_mrp_example"/>
|
||||
<field name="product_qty">15</field>
|
||||
<field name="location_id" ref="stock.stock_location_stock"/>
|
||||
</record>
|
||||
<function model="stock.inventory" name="action_done">
|
||||
<function eval="[[('id', '=', ref('stock_inventory_mrp_example'))]]" model="stock.inventory" name="search"/>
|
||||
</function>
|
||||
|
||||
</odoo>
|
||||
81
multi_level_mrp/demo/mrp_bom_demo.xml
Normal file
81
multi_level_mrp/demo/mrp_bom_demo.xml
Normal file
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
<!-- FP-1 -->
|
||||
<record id="mrp_bom_fp_1" model="mrp.bom">
|
||||
<field name="product_tmpl_id"
|
||||
ref="product_product_fp_1_product_template"/>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
</record>
|
||||
<record id="mrp_bom_fp_1_line_pp_1" model="mrp.bom.line">
|
||||
<field name="product_id" ref="product_product_pp_1"/>
|
||||
<field name="product_qty">2</field>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
<field name="bom_id" ref="mrp_bom_fp_1"/>
|
||||
</record>
|
||||
<record id="mrp_bom_fp_1_line_pp_2" model="mrp.bom.line">
|
||||
<field name="product_id" ref="product_product_pp_2"/>
|
||||
<field name="product_qty">3</field>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
<field name="bom_id" ref="mrp_bom_fp_1"/>
|
||||
</record>
|
||||
|
||||
<!-- FP-2 -->
|
||||
<record id="mrp_bom_fp_2" model="mrp.bom">
|
||||
<field name="product_tmpl_id"
|
||||
ref="product_product_fp_2_product_template"/>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
</record>
|
||||
<record id="mrp_bom_fp_2_line_sf_1" model="mrp.bom.line">
|
||||
<field name="product_id" ref="product_product_sf_1"/>
|
||||
<field name="product_qty">2</field>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
<field name="bom_id" ref="mrp_bom_fp_2"/>
|
||||
</record>
|
||||
<record id="mrp_bom_fp_2_line_sf_2" model="mrp.bom.line">
|
||||
<field name="product_id" ref="product_product_sf_2"/>
|
||||
<field name="product_qty">3</field>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
<field name="bom_id" ref="mrp_bom_fp_2"/>
|
||||
</record>
|
||||
<!-- SF-1 -->
|
||||
<record id="mrp_bom_sf_1" model="mrp.bom">
|
||||
<field name="product_tmpl_id"
|
||||
ref="product_product_sf_1_product_template"/>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
</record>
|
||||
<record id="mrp_bom_sf_1_line_pp_1" model="mrp.bom.line">
|
||||
<field name="product_id" ref="product_product_pp_1"/>
|
||||
<field name="product_qty">3</field>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
<field name="bom_id" ref="mrp_bom_sf_1"/>
|
||||
</record>
|
||||
<record id="mrp_bom_sf_1_line_pp_2" model="mrp.bom.line">
|
||||
<field name="product_id" ref="product_product_pp_2"/>
|
||||
<field name="product_qty">2</field>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
<field name="bom_id" ref="mrp_bom_sf_1"/>
|
||||
</record>
|
||||
<!-- SF-2 -->
|
||||
<record id="mrp_bom_sf_2" model="mrp.bom">
|
||||
<field name="product_tmpl_id"
|
||||
ref="product_product_sf_2_product_template"/>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
</record>
|
||||
<record id="mrp_bom_sf_2_line_pp_2" model="mrp.bom.line">
|
||||
<field name="product_id" ref="product_product_pp_2"/>
|
||||
<field name="product_qty">3</field>
|
||||
<field name="product_uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="sequence">5</field>
|
||||
<field name="bom_id" ref="mrp_bom_sf_2"/>
|
||||
</record>
|
||||
</odoo>
|
||||
6
multi_level_mrp/demo/product_category_demo.xml
Normal file
6
multi_level_mrp/demo/product_category_demo.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
<record id="product_category_mrp" model="product.category">
|
||||
<field name="name">MRP</field>
|
||||
</record>
|
||||
</odoo>
|
||||
59
multi_level_mrp/demo/product_product_demo.xml
Normal file
59
multi_level_mrp/demo/product_product_demo.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
<record id="product_product_fp_1" model="product.product">
|
||||
<field name="name">FP-1</field>
|
||||
<field name="categ_id" ref="product_category_mrp"/>
|
||||
<field name="type">product</field>
|
||||
<field name="uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="uom_po_id" ref="product.product_uom_unit"/>
|
||||
<field name="produce_delay">2</field>
|
||||
<field name="route_ids" eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"/>
|
||||
</record>
|
||||
|
||||
<record id="product_product_fp_2" model="product.product">
|
||||
<field name="name">FP-2</field>
|
||||
<field name="categ_id" ref="product_category_mrp"/>
|
||||
<field name="type">product</field>
|
||||
<field name="uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="uom_po_id" ref="product.product_uom_unit"/>
|
||||
<field name="produce_delay">1</field>
|
||||
<field name="route_ids" eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"/>
|
||||
</record>
|
||||
|
||||
<record id="product_product_sf_1" model="product.product">
|
||||
<field name="name">SF-1</field>
|
||||
<field name="categ_id" ref="product_category_mrp"/>
|
||||
<field name="type">product</field>
|
||||
<field name="uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="uom_po_id" ref="product.product_uom_unit"/>
|
||||
<field name="produce_delay">1</field>
|
||||
<field name="route_ids" eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"/>
|
||||
</record>
|
||||
<record id="product_product_sf_2" model="product.product">
|
||||
<field name="name">SF-2</field>
|
||||
<field name="categ_id" ref="product_category_mrp"/>
|
||||
<field name="type">product</field>
|
||||
<field name="uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="uom_po_id" ref="product.product_uom_unit"/>
|
||||
<field name="produce_delay">3</field>
|
||||
<field name="route_ids" eval="[(6, 0, [ref('mrp.route_warehouse0_manufacture')])]"/>
|
||||
</record>
|
||||
|
||||
<record id="product_product_pp_1" model="product.product">
|
||||
<field name="name">PP-1</field>
|
||||
<field name="categ_id" ref="product_category_mrp"/>
|
||||
<field name="type">product</field>
|
||||
<field name="uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="uom_po_id" ref="product.product_uom_unit"/>
|
||||
<field name="route_ids" eval="[(6, 0, [ref('purchase.route_warehouse0_buy')])]"/>
|
||||
</record>
|
||||
|
||||
<record id="product_product_pp_2" model="product.product">
|
||||
<field name="name">PP-2</field>
|
||||
<field name="categ_id" ref="product_category_mrp"/>
|
||||
<field name="type">product</field>
|
||||
<field name="uom_id" ref="product.product_uom_unit"/>
|
||||
<field name="uom_po_id" ref="product.product_uom_unit"/>
|
||||
<field name="route_ids" eval="[(6, 0, [ref('purchase.route_warehouse0_buy')])]"/>
|
||||
</record>
|
||||
</odoo>
|
||||
18
multi_level_mrp/demo/product_supplierinfo_demo.xml
Normal file
18
multi_level_mrp/demo/product_supplierinfo_demo.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
<record id="product_supplierinfo_pp_1" model="product.supplierinfo">
|
||||
<field name="product_tmpl_id" ref="product_product_pp_1_product_template"/>
|
||||
<field name="name" ref="res_partner_lazer_tech"/>
|
||||
<field name="delay">4</field>
|
||||
<field name="min_qty">0</field>
|
||||
<field name="price">100</field>
|
||||
</record>
|
||||
|
||||
<record id="product_supplierinfo_pp_2" model="product.supplierinfo">
|
||||
<field name="product_tmpl_id" ref="product_product_pp_2_product_template"/>
|
||||
<field name="name" ref="res_partner_lazer_tech"/>
|
||||
<field name="delay">2</field>
|
||||
<field name="min_qty">0</field>
|
||||
<field name="price">100</field>
|
||||
</record>
|
||||
</odoo>
|
||||
10
multi_level_mrp/demo/res_partner_demo.xml
Normal file
10
multi_level_mrp/demo/res_partner_demo.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo noupdate="1">
|
||||
<record id="res_partner_lazer_tech" model="res.partner">
|
||||
<field name="name">Lazer Tech</field>
|
||||
<field name="is_company">1</field>
|
||||
<field name="company_id" ref="base.main_company"/>
|
||||
<field name="customer" eval="False"/>
|
||||
<field name="supplier" eval="True"/>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -152,40 +152,3 @@ class MrpMove(models.Model):
|
||||
self.current_date = self.mrp_date
|
||||
self.mrp_processed = True
|
||||
self.name = seqnbr
|
||||
|
||||
@api.one
|
||||
def mrp_process(self):
|
||||
self.mrp_process_mo()
|
||||
self.mrp_process_pr()
|
||||
return True
|
||||
|
||||
# TODO: move to new API
|
||||
@api.v7
|
||||
def mrp_process_po(self, cr, uid, ids, context=None):
|
||||
view_id = self.pool.get('ir.ui.view').search(
|
||||
cr, uid, [('model', '=', 'mrp.move.create.po'),
|
||||
('name', '=', 'mrp.move.create.po.form')])
|
||||
move = self.browse(cr, uid, ids)[0]
|
||||
context['move_id'] = move.id
|
||||
context['default_move_id'] = move.id
|
||||
context['default_mrp_qty'] = move.mrp_qty
|
||||
context['default_mrp_date'] = move.mrp_date
|
||||
context['default_qty_po'] = move.mrp_qty
|
||||
context['default_date_po'] = move.mrp_date
|
||||
context['default_main_supplier_id'] = \
|
||||
move.mrp_product_id.main_supplier_id.id
|
||||
context['default_product_id'] = move.mrp_product_id.product_id.id
|
||||
context['default_purchase_line_warn_msg'] = \
|
||||
move.mrp_product_id.product_id.purchase_line_warn_msg
|
||||
context['default_purchase_line_warn'] = \
|
||||
move.mrp_product_id.product_id.purchase_line_warn
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': 'Create PO',
|
||||
'view_mode': 'form',
|
||||
'view_type': 'form',
|
||||
'view_id': view_id[0],
|
||||
'res_model': 'mrp.move.create.po',
|
||||
'target': 'new',
|
||||
'context': context,
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ class MrpProduct(models.Model):
|
||||
select=True)
|
||||
mrp_inspection_delay = fields.Integer(
|
||||
string='Inspection Delay', related='product_id.mrp_inspection_delay')
|
||||
mrp_lead_time = fields.Integer(string='Lead Time',
|
||||
related='product_id.mrp_lead_time')
|
||||
mrp_lead_time = fields.Float(string='Lead Time',
|
||||
related='product_id.produce_delay')
|
||||
mrp_llc = fields.Integer('Low Level Code', select=True)
|
||||
mrp_maximum_order_qty = fields.Float(
|
||||
string='Maximum Order Qty', related='product_id.mrp_maximum_order_qty')
|
||||
|
||||
@@ -19,7 +19,6 @@ class Product(models.Model):
|
||||
mrp_applicable = fields.Boolean('MRP Applicable')
|
||||
mrp_exclude = fields.Boolean('Exclude from MRP')
|
||||
mrp_inspection_delay = fields.Integer('Inspection Delay', default=0)
|
||||
mrp_lead_time = fields.Integer('Lead Time', default=1)
|
||||
mrp_maximum_order_qty = fields.Float('Maximum Order Qty', default=0.00)
|
||||
mrp_minimum_order_qty = fields.Float('Minimum Order Qty', default=0.00)
|
||||
mrp_minimum_stock = fields.Float('Minimum Stock')
|
||||
|
||||
2
multi_level_mrp/tests/__init__.py
Normal file
2
multi_level_mrp/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from . import test_multi_level_mrp
|
||||
60
multi_level_mrp/tests/test_multi_level_mrp.py
Normal file
60
multi_level_mrp/tests/test_multi_level_mrp.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# (http://www.eficent.com)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.tests.common import SavepointCase
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
class TestMultiLevelMRP(SavepointCase):
|
||||
def setUp(self):
|
||||
super(TestMultiLevelMRP, self).setUp()
|
||||
self.wiz_multi_level_mrp_model = self.env['multi.level.mrp']
|
||||
self.stock_picking_model = self.env['stock.picking']
|
||||
self.mrp_inventory_model = self.env['mrp.inventory']
|
||||
self.fp_1 = self.env.ref('multi_level_mrp.product_product_fp_1')
|
||||
self.fp_2 = self.env.ref('multi_level_mrp.product_product_fp_2')
|
||||
self.sf_1 = self.env.ref('multi_level_mrp.product_product_sf_1')
|
||||
self.sf_2 = self.env.ref('multi_level_mrp.product_product_sf_2')
|
||||
self.pp_1 = self.env.ref('multi_level_mrp.product_product_pp_1')
|
||||
self.pp_2 = self.env.ref('multi_level_mrp.product_product_pp_2')
|
||||
self.wh = self.env.ref('stock.warehouse0')
|
||||
self.stock_location = self.wh.lot_stock_id
|
||||
self.customer_location = self.env.ref(
|
||||
'stock.stock_location_customers')
|
||||
date_move = datetime.today() + timedelta(days=7)
|
||||
self.picking_1 = self.stock_picking_model.create({
|
||||
'picking_type_id': self.ref('stock.picking_type_out'),
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id,
|
||||
'move_lines': [
|
||||
(0, 0, {
|
||||
'name': 'Test move pf-1',
|
||||
'product_id': self.fp_1.id,
|
||||
'date_expected': date_move,
|
||||
'date': date_move,
|
||||
'product_uom': self.fp_1.uom_id.id,
|
||||
'product_uom_qty': 100,
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id
|
||||
}),
|
||||
(0, 0, {
|
||||
'name': 'Test move fp-2',
|
||||
'product_id': self.fp_2.id,
|
||||
'date_expected': date_move,
|
||||
'date': date_move,
|
||||
'product_uom': self.fp_2.uom_id.id,
|
||||
'product_uom_qty': 15,
|
||||
'location_id': self.stock_location.id,
|
||||
'location_dest_id': self.customer_location.id
|
||||
})]
|
||||
})
|
||||
self.picking_1.action_confirm()
|
||||
|
||||
def test_mrp_1(self):
|
||||
self.wiz_multi_level_mrp_model.create({}).run_multi_level_mrp()
|
||||
pp_1_inventory_lines = self.mrp_inventory_model.search(
|
||||
[('mrp_product_id.product_id', '=', self.pp_1.id)])
|
||||
self.assertEqual(len(pp_1_inventory_lines), 1)
|
||||
self.assertEqual(pp_1_inventory_lines.demand_qty, 290)
|
||||
self.assertEqual(pp_1_inventory_lines.to_procure, 250)
|
||||
@@ -72,8 +72,6 @@
|
||||
<field name="mrp_type" readonly="True"/>
|
||||
<field name="mrp_move_up_ids" readonly="True"/>
|
||||
<field name="mrp_processed" invisible="True"/>
|
||||
<button name="mrp_process" icon="gtk-go-forward" type="object" attrs="{'invisible': ['|','|',('mrp_action','==', 'none'),('mrp_action','==', 'po'),('mrp_processed','==',True)]}"/>
|
||||
<button name="mrp_process_po" icon="gtk-go-forward" type="object" attrs="{'invisible': ['|',('mrp_action','!=', 'po'),('mrp_processed','==',True)]}"/>
|
||||
</tree>
|
||||
<form string="Moves">
|
||||
<group colspan="4" col="2">
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
<field name="mrp_exclude"/>
|
||||
<field name="mrp_verified"/>
|
||||
<field name="mrp_nbr_days"/>
|
||||
<field name="mrp_lead_time"/>
|
||||
<field name="mrp_transit_delay"/>
|
||||
<field name="mrp_inspection_delay"/>
|
||||
</group>
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
from . import multi_level_mrp
|
||||
from . import mrp_move_create_po
|
||||
from . import mrp_inventory_procure
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
# © 2016 Ucamco - Wim Audenaert <wim.audenaert@ucamco.com>
|
||||
# © 2016 Eficent Business and IT Consulting Services S.L.
|
||||
# - Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from datetime import date
|
||||
|
||||
|
||||
class MrpMoveCreatePo(models.TransientModel):
|
||||
_name = 'mrp.move.create.po'
|
||||
|
||||
move_id = fields.Many2one('mrp.move', 'Move', select=True)
|
||||
product_id = fields.Many2one('product.product', 'Product', select=True)
|
||||
main_supplier_id = fields.Many2one('res.partner', 'Main Supplier',
|
||||
select=True)
|
||||
partner_id = fields.Many2one('res.partner', 'Partner', select=True)
|
||||
mrp_qty = fields.Float('Quantity')
|
||||
mrp_date = fields.Date('Planned Date')
|
||||
qty_po = fields.Float('Quantity PO')
|
||||
date_po = fields.Date('Date PO')
|
||||
other_partner = fields.Boolean('Select Other Partner', default=False)
|
||||
purchase_line_warn = fields.Char('Purchase Warning')
|
||||
purchase_line_warn_msg = fields.Text('Purchase Warning')
|
||||
|
||||
@api.multi
|
||||
def create_po(self):
|
||||
for move in self:
|
||||
if move.other_partner and move.partner_id:
|
||||
partner_selected = move.partner_id.id
|
||||
pricelist = move.partner_id.property_product_pricelist_purchase.id
|
||||
fiscalposition = move.partner_id.property_account_position.id
|
||||
currency_id = \
|
||||
move.partner_id.property_product_pricelist_purchase.\
|
||||
currency_id.id
|
||||
else:
|
||||
partner_selected = move.main_supplier_id.id
|
||||
pricelist = move.main_supplier_id.\
|
||||
property_product_pricelist_purchase.id
|
||||
fiscalposition = \
|
||||
move.main_supplier_id.property_account_position.id
|
||||
currency_id = move.main_supplier_id.\
|
||||
property_product_pricelist_purchase.currency_id.id
|
||||
|
||||
order_id = 0
|
||||
sql_stat = "SELECT id FROM purchase_order WHERE " \
|
||||
"purchase_order.partner_id = %d AND state = 'draft' " \
|
||||
"ORDER BY date_order DESC LIMIT 1" % \
|
||||
(partner_selected, )
|
||||
self.env.cr.execute(sql_stat)
|
||||
sql_res = self.env.cr.dictfetchone()
|
||||
if sql_res:
|
||||
if sql_res['id']:
|
||||
order_id = sql_res['id']
|
||||
|
||||
unit_price = 0
|
||||
sql_stat = "SELECT price FROM product_supplierinfo, " \
|
||||
"pricelist_partnerinfo WHERE " \
|
||||
"product_supplierinfo.name = %d AND product_tmpl_id " \
|
||||
"= %d AND product_supplierinfo.id = suppinfo_id " \
|
||||
"LIMIT 1" % (partner_selected,
|
||||
move.product_id.product_tmpl_id.id)
|
||||
self.env.cr.execute(sql_stat)
|
||||
sql_res = self.env.cr.dictfetchone()
|
||||
if sql_res:
|
||||
if sql_res['price']:
|
||||
unit_price = sql_res['price']
|
||||
|
||||
if order_id == 0:
|
||||
po = self.env['purchase.order']
|
||||
po_id = po.create({
|
||||
'shipped': False,
|
||||
'warehouse_id': 1,
|
||||
'date_order': date.today(),
|
||||
'location_id': 12,
|
||||
'amount_untaxed': 0.00,
|
||||
'partner_id': partner_selected,
|
||||
'company_id': 1,
|
||||
'amount_tax': 0.00,
|
||||
'invoice_method': 'picking',
|
||||
'state': 'draft',
|
||||
'pricelist_id': pricelist,
|
||||
'amount_total': 0.00,
|
||||
'journal_id': 2,
|
||||
'accept_amount': False,
|
||||
'fiscal_position': fiscalposition,
|
||||
'currency_id': currency_id,
|
||||
})
|
||||
order_id = po_id
|
||||
|
||||
if order_id != 0:
|
||||
pr = self.env['purchase.order.line']
|
||||
account_fiscal_position = \
|
||||
self.env['account.fiscal.position']
|
||||
account_tax = self.env['account.tax']
|
||||
fpos = fiscalposition and account_fiscal_position.browse(
|
||||
fiscalposition) or False
|
||||
taxes = account_tax.browse(map(lambda x: x.id,
|
||||
move.product_id.supplier_taxes_id))
|
||||
taxes_ids = account_fiscal_position.map_tax(fpos, taxes)
|
||||
pr_id = pr.create({
|
||||
'product_id': move.product_id.id,
|
||||
'product_uom': move.product_id.product_tmpl_id.uom_id.id,
|
||||
'date_planned': move.date_po,
|
||||
'order_id': order_id,
|
||||
'name': '[' + move.product_id.default_code + '] ' +
|
||||
move.product_id.name,
|
||||
'price_unit': unit_price,
|
||||
'product_qty': move.qty_po,
|
||||
'supplier_uom_id':
|
||||
move.product_id.product_tmpl_id.uom_id.id,
|
||||
'supplier_price_unit': unit_price,
|
||||
'supplier_qty': move.qty_po,
|
||||
'conversion_coeff': 1,
|
||||
'taxes_id': [[6, False, taxes_ids]],
|
||||
'description': False,
|
||||
})
|
||||
|
||||
order_number = None
|
||||
sql_stat = "SELECT name FROM purchase_order WHERE id = %d" % (
|
||||
order_id, )
|
||||
self.env.cr.execute(sql_stat)
|
||||
sql_res = self.env.cr.dictfetchone()
|
||||
if sql_res:
|
||||
if sql_res['name']:
|
||||
order_number = sql_res['name']
|
||||
|
||||
if 'move_id' in self.env.context and self.env.context['move_id']:
|
||||
move_obj = self.env['mrp.move']
|
||||
move_obj.write(self.env.context['move_id'], {
|
||||
'purchase_order_id': order_id,
|
||||
'purchase_order_line_id': pr_id,
|
||||
'mrp_processed': True,
|
||||
'current_qty': move.qty_po,
|
||||
'current_date': move.date_po,
|
||||
'name': order_number,
|
||||
})
|
||||
|
||||
return True
|
||||
@@ -1,33 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="mrp_move_create_po_form">
|
||||
<field name="name">mrp.move.create.po.form</field>
|
||||
<field name="model">mrp.move.create.po</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create PO">
|
||||
<group colspan="4">
|
||||
<group>
|
||||
<field name="move_id" invisible="True"/>
|
||||
<field name="product_id" readonly="True"/>
|
||||
<field name="mrp_qty" readonly="True"/>
|
||||
<field name="qty_po" attrs="{'invisible':[('purchase_line_warn','==','block')]}"/>
|
||||
<field name="mrp_date" readonly="True"/>
|
||||
<field name="date_po" attrs="{'invisible':[('purchase_line_warn','==','block')]}"/>
|
||||
<field name="main_supplier_id" readonly="True"/>
|
||||
<field name="other_partner" attrs="{'invisible':[('purchase_line_warn','==','block')]}"/>
|
||||
<field name="partner_id" attrs="{'invisible':[('other_partner','==',False)]}" domain="[('supplier','=',True),('is_company','=',True)]"/>
|
||||
<field name="purchase_line_warn" invisible="True"/>
|
||||
<field name="purchase_line_warn_msg" readonly="True" attrs="{'invisible':[('purchase_line_warn','==','no-message')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group colspan="4" col="4">
|
||||
<button string="Create PO" name="create_po" icon="gtk-ok" type="object" attrs="{'invisible':[('purchase_line_warn','==','block')]}"/>
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -134,9 +134,9 @@ class MultiLevelMrp(models.TransientModel):
|
||||
order_number = move.name
|
||||
mrp_date = date.today()
|
||||
if datetime.date(datetime.strptime(
|
||||
move.date, '%Y-%m-%d %H:%M:%S')) > date.today():
|
||||
move.date_expected, '%Y-%m-%d %H:%M:%S')) > date.today():
|
||||
mrp_date = datetime.date(datetime.strptime(
|
||||
move.date, '%Y-%m-%d %H:%M:%S'))
|
||||
move.date_expected, '%Y-%m-%d %H:%M:%S'))
|
||||
return {
|
||||
'mrp_area_id': mrp_product.mrp_area_id.id,
|
||||
'product_id': move.product_id.id,
|
||||
@@ -150,7 +150,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
'mrp_qty': productqty,
|
||||
'current_qty': productqty,
|
||||
'mrp_date': mrp_date,
|
||||
'current_date': move.date,
|
||||
'current_date': move.date_expected,
|
||||
'mrp_action': 'none',
|
||||
'mrp_type': mrp_type,
|
||||
'mrp_processed': False,
|
||||
@@ -296,17 +296,6 @@ class MultiLevelMrp(models.TransientModel):
|
||||
for bomline in bom.bom_line_ids:
|
||||
if bomline.product_qty <= 0.00:
|
||||
continue
|
||||
if bomline.date_start and datetime.date(
|
||||
datetime.strptime(
|
||||
bomline.date_start, '%Y-%m-%d')) > \
|
||||
mrp_date_demand:
|
||||
continue
|
||||
if bomline.date_stop and datetime.date(
|
||||
datetime.strptime(
|
||||
bomline.date_stop, '%Y-%m-%d')) < \
|
||||
mrp_date_demand:
|
||||
continue
|
||||
|
||||
mrp_date_demand_2 = mrp_date_demand-timedelta(
|
||||
days=(product.mrp_transit_delay+product.
|
||||
mrp_inspection_delay))
|
||||
@@ -895,6 +884,7 @@ class MultiLevelMrp(models.TransientModel):
|
||||
# Read supply actions
|
||||
supply_actions_qty_by_date = {}
|
||||
mrp_type = 's'
|
||||
# TODO: if we remove cancel take it into account here, as well as mrp_type ('r').
|
||||
exclude_mrp_actions = ['none', 'cancel']
|
||||
sql_stat = '''SELECT mrp_date, sum(mrp_qty) as actions_qty
|
||||
FROM mrp_move
|
||||
|
||||
Reference in New Issue
Block a user