[10.0] Migrate mrp_sale_info

- Change workcenter.line to mrp.workorder
- move_prod_id not exist. search sale information from move_finished_ids and changed related field to compute field
- add unit test
This commit is contained in:
bima
2017-06-01 13:31:42 +07:00
parent 0e65000f4b
commit d3ba3dfbff
10 changed files with 134 additions and 78 deletions

View File

@@ -51,6 +51,7 @@ Contributors
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>",
* Ana Juaristi <ajuaristio@gmail.com>"
* Victor M. Martin <victor.martin@elico-corp.com>
* Bima Jati Wijaya <bimajatiwijaya@gmail.com>
Maintainer
----------

View File

@@ -4,7 +4,7 @@
{
"name": "MRP Sale Info",
"summary": "Adds sale information to Manufacturing models",
"version": "9.0.1.0.0",
"version": "10.0.1.0.0",
"category": "Manufacturing",
"website": "http://www.antiun.com",
"author": "Antiun Ingeniería S.L., "
@@ -14,15 +14,14 @@
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
'installable': False,
'installable': True,
"depends": [
"mrp_operations",
"sale_mrp",
"sale_order_dates",
"stock"
],
"data": [
"views/mrp_production.xml",
"views/mrp_production_workcenter_line.xml"
"views/mrp_workorder.xml"
]
}

View File

@@ -3,4 +3,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import mrp_production
from . import mrp_production_workcenter_line
from . import mrp_workorder

View File

@@ -2,16 +2,29 @@
# © 2016 Antiun Ingenieria S.L. - Javier Iniesta
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields
from odoo import api, fields, models
class MrpProduction(models.Model):
_inherit = "mrp.production"
sale_id = fields.Many2one(
'sale.order', string='Sale order', readonly=True, store=True,
related='move_prod_id.procurement_id.sale_line_id.order_id')
partner_id = fields.Many2one(related='sale_id.partner_id',
string='Customer', store=True)
commitment_date = fields.Datetime(related='sale_id.commitment_date',
string='Commitment Date', store=True)
sale_id = fields.Many2one('sale.order', compute='_compute_sale_info', string='Sale order',
readonly=True)
partner_id = fields.Many2one('res.partner', compute='_compute_sale_info',
string='Customer')
commitment_date = fields.Datetime(compute='_compute_sale_info',
string='Commitment Date')
@api.multi
def _compute_sale_info(self):
def get_parent_move(move):
if move.move_dest_id:
return get_parent_move(move.move_dest_id)
return move
for production in self:
move = get_parent_move(production.move_finished_ids)
production.sale_id = move.procurement_id and move.procurement_id.sale_line_id and \
move.procurement_id.sale_line_id.order_id.id or False
production.partner_id = production.sale_id and production.sale_id.partner_id and production.sale_id.partner_id.id or False
production.commitment_date = production.sale_id and production.sale_id.commitment_date or ''

View File

@@ -2,11 +2,11 @@
# © 2016 Antiun Ingenieria S.L. - Javier Iniesta
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields
from odoo import models, fields
class MrpProductionWorkcenterLine(models.Model):
_inherit = "mrp.production.workcenter.line"
class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"
sale_id = fields.Many2one(related='production_id.sale_id',
string='Sale order', readonly=True, store=True)

View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# © 2017 Bima Jati Wijaya
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_sale_manufacture

View File

@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# © 2017 Bima Jati Wijaya
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import TransactionCase
class TestManufactureSale(TransactionCase):
def setUp(self):
super(TestManufactureSale, self).setUp()
self.partner = self.env.ref('base.res_partner_1')
self.mrp_production = self.env['mrp.production']
def test_manufacture(self):
product = self.browse_ref('product.product_product_27')
route1 = self.browse_ref('mrp.route_warehouse0_manufacture')
route2 = self.browse_ref('stock.route_warehouse0_mto')
# add make to order and manufacture routes
product.write({'route_ids': [(6, 0, [route1.id, route2.id])]})
self.assertTrue(product.route_ids)
so = self.env['sale.order'].create({
'partner_id': self.partner.id,
'partner_invoice_id': self.partner.id,
'partner_shipping_id': self.partner.id,
'order_line': [(0, 0, {'name': product.name, 'product_id': product.id, 'product_uom_qty': 1, 'product_uom': product.uom_id.id,
'price_unit': product.list_price})
],
'pricelist_id': self.env.ref('product.list0').id,
})
so.action_confirm()
mrp = self.mrp_production.search([('origin', 'like', so.name+'%')], limit=1)
# checking sale info filled correctly on manufacture
self.assertEqual(so.id, mrp.sale_id.id)
self.assertEqual(self.partner.id, mrp.partner_id.id)
self.assertEqual(so.commitment_date, mrp.commitment_date)

View File

@@ -1,32 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<data>
<record id="mrp_production_form_view" model="ir.ui.view">
<field name="name">MRP Production Form with Sale Order</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="sale_mrp.mrp_production_form_view_inherit_sale_mrp" />
<field name="arch" type="xml">
<field name="sale_name" position="after">
<field name="sale_id"/>
<field name="partner_id"/>
<field name="commitment_date"/>
<record id="mrp_production_form_view" model="ir.ui.view">
<field name="name">MRP Production Form with Sale Order</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view" />
<field name="arch" type="xml">
<field name="availability" position="after">
<field name="sale_id"/>
<field name="partner_id"/>
<field name="commitment_date"/>
</field>
</field>
</field>
</record>
</record>
<record id="mrp_production_tree_view" model="ir.ui.view">
<field name="name">MRP Production Tree with Sale Order</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_tree_view"/>
<field name="arch" type="xml">
<field name="date_planned" position="after">
<field name="sale_id"/>
<field name="partner_id"/>
<field name="commitment_date"/>
<record id="mrp_production_tree_view" model="ir.ui.view">
<field name="name">MRP Production Tree with Sale Order</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_tree_view"/>
<field name="arch" type="xml">
<field name="date_planned_start" position="after">
<field name="sale_id"/>
<field name="partner_id"/>
<field name="commitment_date"/>
</field>
</field>
</field>
</record>
</record>
</data>
</openerp>
</data>
</odoo>

View File

@@ -1,36 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="mrp_production_workcenter_tree_view_inherit" model="ir.ui.view">
<field name="name">MRP Production Work Order Tree with Sale Order</field>
<field name="model">mrp.production.workcenter.line</field>
<field name="inherit_id" ref="mrp_operations.mrp_production_workcenter_tree_view_inherit"/>
<field name="arch" type="xml">
<field name="date_planned" position="after">
<field name="sale_id"/>
<field name="partner_id"/>
<field name="commitment_date"/>
</field>
</field>
</record>
<record id="mrp_production_workcenter_form_view_inherit" model="ir.ui.view">
<field name="name">MRP Production Work Order Form with Sale Order</field>
<field name="model">mrp.production.workcenter.line</field>
<field name="inherit_id" ref="mrp_operations.mrp_production_workcenter_form_view_inherit"/>
<field name="arch" type="xml">
<xpath expr="//page/group[1]" position="after">
<group string="Sale Information">
<field name="sale_id"/>
<field name="partner_id"/>
<field name="commitment_date"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="mrp_production_workcenter_tree_view_inherit" model="ir.ui.view">
<field name="name">MRP Production Work Order Tree with Sale Order</field>
<field name="model">mrp.workorder</field>
<field name="inherit_id" ref="mrp.mrp_production_workcenter_tree_view_inherit"/>
<field name="arch" type="xml">
<field name="date_planned_start" position="after">
<field name="sale_id"/>
<field name="partner_id"/>
<field name="commitment_date"/>
</field>
</field>
</record>
<record id="mrp_workorder_sale_form_view_inherit" model="ir.ui.view">
<field name="name">MRP Production Work Order Form with Sale Order</field>
<field name="model">mrp.workorder</field>
<field name="inherit_id" ref="mrp.mrp_production_workcenter_form_view_inherit"/>
<field name="arch" type="xml">
<xpath expr="//page/group[1]" position="after">
<group string="Sale Information">
<field name="sale_id"/>
<field name="partner_id"/>
<field name="commitment_date"/>
</group>
</xpath>
</field>
</record>
</data>
</odoo>