Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] put_in_pack_stock: Created custom put in pack module #647

Draft
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions put_in_pack_stock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions put_in_pack_stock/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
'name': 'Put In Pack -Stock',
'category': 'Stock/PutInPack2',
'summary': 'Full Traceability Report Demo Data',
'author': 'Odoo S.A.',
'depends': ['stock','purchase'],
'description': "Custom put in pack button for Inventory Transfer",
'license': 'LGPL-3',
'installable': True,
'data': [
'views/view_custom_put_in_pack.xml',
'views/view_stock_move_put_in_pack.xml',
'views/stock_move_views.xml',
'views/stock_quant_views.xml',
]
}
2 changes: 2 additions & 0 deletions put_in_pack_stock/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import stock_picking
from . import stock_move
82 changes: 82 additions & 0 deletions put_in_pack_stock/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from odoo import api, models, fields


class StockMove(models.Model):
_inherit = 'stock.move'

put_in_pack_toggle = fields.Boolean(
string="Put In Pack",
related="picking_type_id.put_in_pack_toggle"
)
package_qty = fields.Integer(
string = "Package Qty:",
help="Package Quantity",
default=1
)
package_type = fields.Selection(
selection = [
('box', "Box"),
('carton', "Carton")
],
string="Package Type",
help="Package Type for the Product to be kept in the package."
)
package_size = fields.Integer(
string="Package Size",
help="How many quantity of the particular product will go into the package",
default=0
)

def action_custom_put_in_pack(self):
self.ensure_one()
if self.product_uom_qty <= 0:
raise UserError("No quantity available to package.")
self.move_line_ids.unlink()
package = self.env['stock.quant.package'].create({
'name': f"{self.product_id.name} Package"
})
self.env['stock.move.line'].create({
'move_id': self.id,
'result_package_id': package.id,
'qty_done': self.product_uom_qty,
'product_id': self.product_id.id,
'product_uom_id': self.product_id.uom_id.id,
})
def action_generate_package(self):
self.ensure_one()
self.move_line_ids.unlink()
if self.has_tracking == 'none':
demand = self.product_uom_qty
correct_uom = self.product_id.uom_id.id
if not correct_uom:
raise ValueError(f"Product {self.product_id.name} does not have a valid UoM set!")
for _ in range(self.package_qty):
if demand <= 0:
break
package = self.env['stock.quant.package'].create({'name': f"{self.product_id.name} Package"})
qty_to_pack = min(demand, self.package_size)
move_line = self.env['stock.move.line'].create({
'move_id': self.id,
'result_package_id': package.id,
'qty_done': qty_to_pack,
'product_id': self.product_id.id,
'product_uom_id': correct_uom,
})
demand -= qty_to_pack
elif self.has_tracking=='lot':
correct_uom = self.product_id.uom_id.id
for line in self.move_line_ids:
lot_quantity = line.quantity
while lot_quantity:
package = self.env['stock.quant.package'].create({'name': f"{self.product_id.name} Package"})
qty_to_pack = min(lot_quantity, self.package_size)
move_line = self.env['stock.move.line'].create({
'move_id': self.id,
'lot_id': line.lot_id.id,
'lot_name': line.lot_name,
'result_package_id': package.id,
'qty_done': qty_to_pack,
'product_id': self.product_id.id,
'product_uom_id': correct_uom,
})
lot_quantity -= qty_to_pack
16 changes: 16 additions & 0 deletions put_in_pack_stock/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from odoo import fields, models


class PickingType(models.Model):
_inherit = "stock.picking.type"

put_in_pack_toggle = fields.Boolean(
string = "Put In Pack"
)

class Picking(models.Model):
_inherit = "stock.picking"

put_in_pack_toggle = fields.Boolean(
related="picking_type_id.put_in_pack_toggle"
)
17 changes: 17 additions & 0 deletions put_in_pack_stock/views/stock_move_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<odoo>
<record id="view_detailed_operation_custom" model="ir.ui.view">
<field name="name">Detailed Operation Inherit</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_stock_move_operations"/>
<field name="arch" type="xml">
<xpath expr="//form/group/group" position="after">
<group invisible="not put_in_pack_toggle">
<field name="package_qty" invisible="has_tracking not in ('none')"/>
<field name="package_size"/>
<field name="package_type"/>
<button name="action_generate_package" type="object" class="btn-primary" string="Generate Packages"/>
</group>
</xpath>
</field>
</record>
</odoo>
12 changes: 12 additions & 0 deletions put_in_pack_stock/views/stock_quant_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo>
<record id="view_stock_quant_tree_inherit" model="ir.ui.view">
<field name="name">stock.quant.tree.inherit</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.quant_search_view"/>
<field name="arch" type="xml">
<xpath expr="//filter[@name='company']" position="after">
<filter name="group_by_packaging" string="Packaging" domain="[]" context="{'group_by': 'package_id'}"/>
</xpath>
</field>
</record>
</odoo>
12 changes: 12 additions & 0 deletions put_in_pack_stock/views/view_custom_put_in_pack.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo>
<record id="view_picking_type_tree_inherit" model="ir.ui.view">
<field name="name">Operation types Inherit</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.view_picking_type_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='company_id']" position="before">
<field name="put_in_pack_toggle" string="Put in Pack" widget="boolean_toggle"/>
</xpath>
</field>
</record>
</odoo>
24 changes: 24 additions & 0 deletions put_in_pack_stock/views/view_stock_move_put_in_pack.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<odoo>
<record id="view_picking_form_inherit" model="ir.ui.view">
<field name="name">stock.picking.form.inherit</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form" />
<field name="arch" type="xml">
<xpath expr="//page[@name='operations']//field[@name='quantity']" position="before">
<field name="put_in_pack_toggle"/>
<button
name="action_custom_put_in_pack"
class="btn-secondary"
string="Put in pack"
type="object"
invisible="put_in_pack_toggle != True"/>
</xpath>
<xpath expr="//page[@name='operations']//field[@name='product_packaging_id']" position="attributes">
<attribute name="column_invisible">parent.put_in_pack_toggle</attribute>
</xpath>
<xpath expr="//page[@name='operations']//button[@name='action_put_in_pack']" position="attributes">
<attribute name="invisible">state in ('draft', 'done', 'cancel') or put_in_pack_toggle</attribute>
</xpath>
</field>
</record>
</odoo>