[MIG] mrp_bom_location: Migration to Odoo 11

This commit is contained in:
mpanarin
2018-02-12 18:44:35 +02:00
committed by Lois Rilo
parent d7fbd6bff4
commit 5f345b1e36
9 changed files with 61 additions and 61 deletions

View File

@@ -1,4 +1,4 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3
@@ -23,7 +23,7 @@ To use this module, you need to:
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/129/9.0
:target: https://runbot.odoo-community.org/runbot/129/11.0
Bug Tracker
===========

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,16 +1,14 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "MRP BOM Location",
"summary": "Adds location field to Bill of Materials and its components.",
"version": "9.0.1.0.0",
"version": "11.0.1.0.0",
"category": "Manufacture",
"website": "https://odoo-community.org/",
"website": "https://github.com/OCA/manufacture",
"author": "Eficent, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"mrp",
],

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,23 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models
from odoo import fields, models
class MrpBom(models.Model):
_inherit = "mrp.bom"
location_id = fields.Many2one(
comodel_name="stock.location", string="Location",
help="Set the preferred location for this BOM.",
domain=[('usage', '=', 'internal')])
related='picking_type_id.default_location_dest_id',
store=True,
)
class MrpBom(models.Model):
class MrpBomLine(models.Model):
_inherit = "mrp.bom.line"
location_id = fields.Many2one(
comodel_name="stock.location", string="Location",
help="Location which it is expected to get the products from.",
domain=[('usage', '=', 'internal')])
related='bom_id.picking_type_id.default_location_src_id',
store=True,
)

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -1,47 +1,64 @@
# -*- coding: utf-8 -*-
# © 2017 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 openerp.osv import osv
from openerp.report import report_sxw
from odoo import api, models
class bom_structure(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(bom_structure, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'get_children': self.get_children,
})
class BomStructureReport(models.AbstractModel):
_name = 'report.mrp.mrp_bom_structure_report'
def get_children(self, record, level=0):
@staticmethod
def _get_child_vals(record, level, qty, uom):
child = {
'pname': record.product_id.name_get()[0][1],
'pcode': record.product_id.default_code,
'puom': record.product_uom_id,
'uname': record.product_uom_id.name,
'level': level,
'code': record.bom_id.code,
'location_name': record.location_id.complete_name or '',
}
qty_per_bom = record.bom_id.product_qty
if uom:
if uom != record.bom_id.product_uom_id:
qty = uom._compute_quantity(qty, record.bom_id.product_uom_id)
child['pqty'] = (record.product_qty * qty) / qty_per_bom
else:
# for the first case, the ponderation is right
child['pqty'] = (record.product_qty * qty)
return child
def get_children(self, records, level=0):
result = []
def _get_rec(record, level, qty=1.0):
for l in record:
res = {}
res['pname'] = l.product_id.name_get()[0][1]
res['pcode'] = l.product_id.default_code
res['pqty'] = l.product_qty * qty
res['uname'] = l.product_uom.name
res['level'] = level
res['code'] = l.bom_id.code
res['location_name'] = l.location_id.complete_name or ''
result.append(res)
def _get_children_recursive(records, level, qty=1.0, uom=None):
for l in records:
child = self._get_child_vals(l, level, qty, uom)
result.append(child)
if l.child_line_ids:
if level < 6:
level += 1
_get_rec(l.child_line_ids, level, qty=res['pqty'])
_get_children_recursive(
l.child_line_ids,
level,
qty=child['pqty'],
uom=child['puom']
)
if level > 0 and level < 6:
level -= 1
return result
children = _get_rec(record, level)
children = _get_children_recursive(records, level)
return children
class report_mrpbomstructure_location(osv.AbstractModel):
_inherit = 'report.mrp.report_mrpbomstructure'
_template = 'mrp.report_mrpbomstructure'
_wrapped_report_class = bom_structure
@api.multi
def get_report_values(self, docids, data=None):
return {
'doc_ids': docids,
'doc_model': 'mrp.bom',
'docs': self.env['mrp.bom'].browse(docids),
'get_children': self.get_children,
'data': data,
}

View File

@@ -8,9 +8,9 @@
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<label for="routing_id" position="before">
<field name="routing_id" position="before">
<field name="location_id"/>
</label>
</field>
<xpath expr="//field[@name='bom_line_ids']/tree/field[@name='product_qty']" position="after">
<field name="location_id"/>
</xpath>
@@ -47,18 +47,7 @@
<field name="model">mrp.bom.line</field>
<field name="inherit_id" ref="mrp.mrp_bom_component_tree_view"/>
<field name="arch" type="xml">
<field name="date_start" position="before">
<field name="location_id"/>
</field>
</field>
</record>
<record id="mrp_bom_line_tree_view" model="ir.ui.view">
<field name="name">mrp.bom.tree - mrp_bom_location</field>
<field name="model">mrp.bom.line</field>
<field name="inherit_id" ref="mrp.mrp_bom_line_tree_view"/>
<field name="arch" type="xml">
<field name="date_start" position="before">
<field name="product_id" position="before">
<field name="location_id"/>
</field>
</field>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_mrpbomstructure_location"
inherit_id="mrp.report_mrpbomstructure">
inherit_id="mrp.mrp_bom_structure_report">
<xpath expr="//thead/tr" position="inside">
<th>Location</th>
</xpath>