Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by rousseldenis
- Loading branch information
Showing
6 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# coding: utf-8 | ||
# © 2017 David BEAL @ Akretion | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _, models, api, fields | ||
|
||
|
||
class QuickAddProductLocation(models.TransientModel): | ||
_name = "quick.add.product.location" | ||
|
||
def _default_putaway(self): | ||
""" Overridable method | ||
""" | ||
return self.env.ref( | ||
"stock_putaway_product.product_putaway_per_product_wh", | ||
raise_if_not_found=False, | ||
) | ||
|
||
putaway_id = fields.Many2one( | ||
comodel_name="product.putaway", | ||
string="Put Away Method", | ||
required=True, | ||
default=lambda self: self._default_putaway(), | ||
) | ||
fixed_location_id = fields.Many2one( | ||
comodel_name="stock.location", string="Location", required=True | ||
) | ||
product_ids = fields.Many2many( | ||
comodel_name="product.product", string="Products", required=True | ||
) | ||
|
||
@api.model | ||
def default_get(self, fields): | ||
res = super(QuickAddProductLocation, self).default_get(fields) | ||
product_ids = self.env.context.get("active_ids") | ||
if product_ids: | ||
res["product_ids"] = product_ids | ||
return res | ||
|
||
@api.multi | ||
def apply_location(self): | ||
self.ensure_one() | ||
products = {} | ||
for product in self.product_ids: | ||
products.setdefault( | ||
product.product_tmpl_id, self.env["product.product"].browse() | ||
) | ||
products[product.product_tmpl_id] |= product | ||
# Remove existing putaway locations | ||
self.env["stock.product.putaway.strategy"].search( | ||
[ | ||
("putaway_id", "=", self.putaway_id.id), | ||
("product_product_id", "in", self.product_ids._ids), | ||
] | ||
).unlink() | ||
for template in products: | ||
products[template].write( | ||
{ | ||
"product_putaway_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"putaway_id": self.putaway_id.id, | ||
"product_tmpl_id": template.id, | ||
"fixed_location_id": self.fixed_location_id.id, | ||
}, | ||
) | ||
] | ||
} | ||
) | ||
product_names = ", ".join([x.name for x in self.product_ids]) | ||
return { | ||
"name": _("Updated products putaway: %s" % product_names), | ||
"type": "ir.actions.act_window", | ||
"res_id": self.env.ref("product.product_normal_action").id, | ||
"view_mode": "tree,form", | ||
"res_model": "product.product", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record id="view_model_form" model="ir.ui.view"> | ||
<field name="model">quick.add.product.location</field> | ||
<field name="active" eval="True" /> | ||
<field name="arch" type="xml"> | ||
<form string="Quick Product Putaway"> | ||
<sheet> | ||
<div> | ||
<h2>Set default location by putaway method to products</h2> | ||
</div> | ||
<group> | ||
<field name="putaway_id" widget="radio"/> | ||
<field name="fixed_location_id"/> | ||
</group> | ||
<group col="1"> | ||
<separator string="Products"/> | ||
<field name="product_ids" nolabel="1"/> | ||
</group> | ||
</sheet> | ||
<footer> | ||
<button name="apply_location" string="Apply" | ||
type="object" class="oe_highlight"/> | ||
<button special="cancel" string="Cancel" class="oe_link"/> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="quick_add_product_location_act_window" model="ir.actions.act_window"> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="name">Add Default Stock Location</field> | ||
<field name="res_model">quick.add.product.location</field> | ||
<field name="src_model">product.product</field> | ||
<field name="view_mode">form,tree</field> | ||
<field name="target">new</field> | ||
</record> | ||
<record id="quick_add_product_location_values" model="ir.values"> | ||
<field eval="'client_action_multi'" name="key2"/> | ||
<field eval="'product.product'" name="model"/> | ||
<field name="name">Add Default Stock Location</field> | ||
<field eval="'ir.actions.act_window,'+str(quick_add_product_location_act_window)" name="value"/> | ||
</record> | ||
|
||
</odoo> |