From 303a1c515cdfbb02a0168ddf540fb45baf844cf6 Mon Sep 17 00:00:00 2001 From: santiky Date: Thu, 16 Sep 2021 15:04:34 +0200 Subject: [PATCH] =?UTF-8?q?Acci=C3=B3n=20para=20crear=20una=20albar=C3=A1n?= =?UTF-8?q?=20con=20los=20productos=20seleccionados=20desde=20la=20lista?= =?UTF-8?q?=20y=20sus=20cantidades=20disponibles.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- product_create_stock_picking/__init__.py | 2 + product_create_stock_picking/__manifest__.py | 28 +++++++++++ product_create_stock_picking/data/data.xml | 16 +++++++ .../models/__init__.py | 2 + .../models/product_template.py | 46 +++++++++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 product_create_stock_picking/__init__.py create mode 100644 product_create_stock_picking/__manifest__.py create mode 100644 product_create_stock_picking/data/data.xml create mode 100644 product_create_stock_picking/models/__init__.py create mode 100644 product_create_stock_picking/models/product_template.py diff --git a/product_create_stock_picking/__init__.py b/product_create_stock_picking/__init__.py new file mode 100644 index 0000000..899bcc9 --- /dev/null +++ b/product_create_stock_picking/__init__.py @@ -0,0 +1,2 @@ +from . import models + diff --git a/product_create_stock_picking/__manifest__.py b/product_create_stock_picking/__manifest__.py new file mode 100644 index 0000000..37b527a --- /dev/null +++ b/product_create_stock_picking/__manifest__.py @@ -0,0 +1,28 @@ +{ + 'name': 'Product Create Stock Picking', + 'category': 'Warehouse', + 'summary': 'Add an action to create a stock picking from a selection of products.', + 'version': '12.0.0.0.1', + 'description': """ + +Add an action to create a stock picking from a selection of products. + +""", + 'author': 'Criptomart', + 'depends': [ + 'stock', + ], + 'external_dependencies': {'python': [], 'bin': []}, + 'data': [ + 'data/data.xml', + ], + 'qweb': [], + 'demo': [], + 'installable': True, + 'auto_install': False, + 'application': True, + "post_load": None, + "pre_init_hook": None, + "post_init_hook": None, + "uninstall_hook": None, +} diff --git a/product_create_stock_picking/data/data.xml b/product_create_stock_picking/data/data.xml new file mode 100644 index 0000000..c015eb1 --- /dev/null +++ b/product_create_stock_picking/data/data.xml @@ -0,0 +1,16 @@ + + + + + Transfiere éstos productos + ir.actions.server + + code + action =records.create_stock_picking() + + action + + + + + diff --git a/product_create_stock_picking/models/__init__.py b/product_create_stock_picking/models/__init__.py new file mode 100644 index 0000000..09ff977 --- /dev/null +++ b/product_create_stock_picking/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_template + diff --git a/product_create_stock_picking/models/product_template.py b/product_create_stock_picking/models/product_template.py new file mode 100644 index 0000000..5559b65 --- /dev/null +++ b/product_create_stock_picking/models/product_template.py @@ -0,0 +1,46 @@ +# Copyright (C) 2021: Criptomart (https://criptomart.net) +# @author Santi Noreña () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +#import logging + +from odoo import tools, models, fields, api, _ + +#_logger = logging.getLogger(__name__) + +class ProductTemplate(models.Model): + _inherit = "product.template" + + @api.multi + def create_stock_picking(self): + picking_vals = self.env['stock.picking'].default_get(self.env['stock.picking']._fields.keys()) + picking_vals.update({ + 'picking_type_id' : self.env.ref('stock.picking_type_internal').id, + 'location_id': self.env.ref('stock.stock_location_stock').id, + 'location_dest_id': self.env.ref('stock.stock_location_stock').id, + }) + picking = self.env['stock.picking'].create(picking_vals) + + for p in self: + _logger.warning("product : %s" %p.name) + move_vals = { + 'name': p.name, + 'product_id': p.id, + 'product_uom_qty': p.qty_available, + 'product_uom': p.uom_id.id, + 'picking_id': picking.id, + 'location_id': self.env.ref('stock.stock_location_stock').id, + 'location_dest_id': self.env.ref('stock.stock_location_stock').id, + 'state': 'waiting', + 'procure_method': 'make_to_order', + } + picking.move_lines = [(0, 0, move_vals)] + + views = [(self.env.ref('stock.view_picking_form').id, 'form')] + return { + 'type': 'ir.actions.act_window', + 'res_model': 'stock.picking', + 'res_id': picking.id, + 'target': 'current', + 'views': views, + }