ソースを参照

Colocar el link de producción en el pedido de ventas.

sebas 3 年 前
コミット
d841c6200f

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+import models

+ 29 - 0
__openerp__.py

@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+
+{
+    'name': 'Sale MRP Link',
+    'version': '8.1',
+    'author' : 'Show manufacturing orders generated from sales order',
+    'website': 'www.eiru.py',
+    'description': """
+
+Funcionalidad:
+ - Show manufacturing orders generated from sales order.
+
+
+    """,
+
+    'category': 'Manufacturing',
+    'depends': [
+        'sale_mrp'
+    ],
+
+    'data': [
+        'views/mrp_production.xml'
+    ],
+
+    'installable': True,
+}
+
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

+ 3 - 0
models/__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+import mrp_production

+ 48 - 0
models/mrp_production.py

@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#                                                                               #
+#    product_genre for OpenERP                                                  #
+#    Author: Victor Obrist                                                      #
+#    contact: victor@paraguayenlaweb.com                                        #
+#                                                                               #
+#    This program is free software: you can redistribute it and/or modify       #
+#    it under the terms of the GNU Affero General Public License as             #
+#    published by the Free Software Foundation, either version 3 of the         #
+#    License, or (at your option) any later version.                            #
+#                                                                               #
+#    This program is distributed in the hope that it will be useful,            #
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of             #
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              #
+#    GNU Affero General Public License for more details.                        #
+#                                                                               #
+#    You should have received a copy of the GNU Affero General Public License   #
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.      #
+#                                                                               #
+#################################################################################
+from openerp import api, fields, models
+
+class MrpProduction(models.Model):
+    _inherit = 'mrp.production'
+
+    partner_id = fields.Many2one(
+        comodel_name='res.partner', string='Customer', store=True,
+        related='move_prod_id.procurement_id.sale_line_id.order_id.partner_id')
+    sale_order_id = fields.Many2one(
+        comodel_name='sale.order', string='Sale Order', store=True,
+        related='move_prod_id.procurement_id.sale_line_id.order_id')
+    sale_line_id = fields.Many2one(
+        comodel_name='sale.order.line', string='Sale Line', store=True,
+        related='move_prod_id.procurement_id.sale_line_id')
+
+
+class Sale(models.Model):
+    _inherit = 'sale.order'
+
+    production_ids = fields.One2many(comodel_name='mrp.production', inverse_name='sale_order_id', string='Production')
+
+    production_count = fields.Integer(compute="_get_production_count")
+
+    @api.one
+    def _get_production_count(self):
+        if self.production_ids:
+            self.production_count = len(self.production_ids)

+ 22 - 0
models/procurement_order.py

@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Copyright 2018 Alex Comba - Agile Business Group
+# Copyright 2016-2018 Akretion
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+
+from openerp import api, models, exceptions, _
+
+
+class ProcurementOrder(models.Model):
+    _inherit = 'procurement.order'
+
+    @api.model
+    def _prepare_mo_vals(self, bom):
+        vals = super(ProcurementOrder, self)._prepare_mo_vals(bom)
+        if self.group_id:
+            sales = self.env['sale.order'].search(
+                [('procurement_group_id', '=', self.group_id.id)])
+            if len(sales) > 1:
+                raise exceptions.ValidationError(
+                    _('More than 1 sale order found for this group'))
+            vals['sale_order_id'] = sales.id
+        return vals

+ 48 - 0
models/sale_order.py

@@ -0,0 +1,48 @@
+# -*- encoding: utf-8 -*-
+#################################################################################
+#                                                                               #
+#    product_genre for OpenERP                                                  #
+#    Author: Victor Obrist                                                      #
+#    contact: victor@paraguayenlaweb.com                                        #
+#                                                                               #
+#    This program is free software: you can redistribute it and/or modify       #
+#    it under the terms of the GNU Affero General Public License as             #
+#    published by the Free Software Foundation, either version 3 of the         #
+#    License, or (at your option) any later version.                            #
+#                                                                               #
+#    This program is distributed in the hope that it will be useful,            #
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of             #
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              #
+#    GNU Affero General Public License for more details.                        #
+#                                                                               #
+#    You should have received a copy of the GNU Affero General Public License   #
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.      #
+#                                                                               #
+#################################################################################
+from openerp import api, fields, models
+
+class SaleOrder(models.Model):
+    _inherit = 'sale.order'
+
+    production_count = fields.Integer(
+        compute='_compute_production_count')
+
+    @api.multi
+    def _compute_production_count(self):
+        mrp_production_model = self.env['mrp.production']
+        for sale in self:
+            domain = [('sale_order_id', '=', sale.id)]
+            sale.production_count = mrp_production_model.search_count(domain)
+
+    @api.multi
+    def action_view_production(self):
+        action = self.env.ref('mrp.mrp_production_action').read()[0]
+        productions = self.env['mrp.production'].search(
+            [('sale_order_id', 'in', self.ids)])
+        if len(productions) > 1:
+            action['domain'] = [('id', 'in', productions.ids)]
+        else:
+            action['views'] = [
+                (self.env.ref('mrp.mrp_production_form_view').id, 'form')]
+            action['res_id'] = productions.id
+        return action

BIN
static/description/icon.png


+ 53 - 0
views/mrp_production.xml

@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+      <record id="act_so_2_mo" model="ir.actions.act_window">
+          <field name="name">Production</field>
+          <field name="res_model">mrp.production</field>
+          <field name="view_type">form</field>
+          <field name="view_mode">tree,form,graph</field>
+          <field name="context">{'search_default_sale_order_id': active_id}</field>
+      </record>
+
+      <record id="sale_order_form_buttons" model="ir.ui.view">
+          <field name="name">sale.order.form.buttons</field>
+          <field name="model">sale.order</field>
+          <field name="inherit_id" ref="sale.view_order_form"/>
+          <field name="priority" eval="30"/>
+          <field name="arch" type="xml">
+              <xpath expr="//h1" position="attributes">
+                  <attribute name="class">oe_left</attribute>
+              </xpath>
+              <xpath expr="//h1" position="after">
+                  <div class="oe_right oe_button_box" name="buttons">
+                      <button class="oe_inline oe_stat_button" type="action"
+                              name="%(act_so_2_mo)d"
+                              attrs="{'invisible': [('production_count', '=', 0)]}"
+                              icon="fa-gears">
+                          <field string="Production" name="production_count" widget="statinfo"/>
+                      </button>
+                  </div>
+              </xpath>
+          </field>
+      </record>
+
+      <record id="mrp_production_sale_info_search_view" model="ir.ui.view">
+          <field name="name">mrp.production.sale.info.search</field>
+          <field name="model">mrp.production</field>
+          <field name="inherit_id" ref="mrp.view_mrp_production_filter"/>
+          <field name="arch" type="xml">
+              <field name="product_id" position="after">
+                  <field name="partner_id" string="Customer"/>
+                  <field name="sale_order_id" string="Sale Order"/>
+              </field>
+              <filter string="Product" position="before">
+                  <filter string="Customer" icon="terp-accessories-archiver"
+                          domain="[]" context="{'group_by':'partner_id'}"/>
+                  <filter string="Sale Order" icon="terp-accessories-archiver"
+                          domain="[]" context="{'group_by':'sale_order_id'}"/>
+              </filter>
+          </field>
+      </record>
+
+  </data>
+</openerp>