size
int64 0
304k
| ext
stringclasses 1
value | lang
stringclasses 1
value | branch
stringclasses 1
value | content
stringlengths 0
304k
| avg_line_length
float64 0
238
| max_line_length
int64 0
304k
|
|---|---|---|---|---|---|---|
7,177
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from dateutil.rrule import MONTHLY
from odoo import fields
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
class TestStockDemandEstimate(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.res_users_model = cls.env["res.users"]
cls.product_model = cls.env["product.product"]
cls.stock_location_model = cls.env["stock.location"]
cls.estimate_model = cls.env["stock.demand.estimate"]
cls.g_stock_manager = cls.env.ref("stock.group_stock_manager")
cls.g_stock_user = cls.env.ref("stock.group_stock_user")
cls.company = cls.env.ref("base.main_company")
# Create users:
cls.manager = cls._create_user(
"user_1",
[cls.g_stock_manager],
cls.company,
).id
cls.user = cls._create_user(
"user_2",
[cls.g_stock_user],
cls.company,
).id
cls.drt_monthly = cls.env["date.range.type"].create(
{"name": "Month", "allow_overlap": False}
)
generator = cls.env["date.range.generator"].create(
{
"date_start": "1943-01-01",
"name_prefix": "1943-",
"type_id": cls.drt_monthly.id,
"duration_count": 1,
"unit_of_time": str(MONTHLY),
"count": 12,
}
)
generator.action_apply()
# Create a product:
cls.product_1 = cls.product_model.create(
{"name": "Test Product 1", "type": "product", "default_code": "PROD1"}
)
# Create a location:
cls.location = cls.stock_location_model.create(
{"name": "Place", "usage": "production"}
)
@classmethod
def _create_user(cls, login, groups, company):
group_ids = [group.id for group in groups]
user = cls.res_users_model.create(
{
"name": login,
"login": login,
"password": "demo",
"email": "example@yourcompany.com",
"company_id": company.id,
"company_ids": [(4, company.id)],
"groups_id": [(6, 0, group_ids)],
}
)
return user
def test_01_demand_estimate_wizard(self):
"""Tests creation of demand estimates using wizard."""
sheets = self.env["stock.demand.estimate.sheet"].search([])
for sheet in sheets:
sheet.unlink()
wiz = self.env["stock.demand.estimate.wizard"]
wiz = wiz.create(
{
"date_start": "1943-01-01",
"date_end": "1943-12-31",
"location_id": self.location.id,
"date_range_type_id": self.drt_monthly.id,
"product_ids": [(6, 0, [self.product_1.id])],
}
)
wiz.create_sheet()
sheets = self.env["stock.demand.estimate.sheet"].search([])
for sheet in sheets:
self.assertEqual(
len(sheet.line_ids),
12,
"There should be 12 lines.",
)
self.assertEqual(
fields.Date.to_string(sheet.date_start),
"1943-01-01",
"The date start should be 1943-01-01",
)
self.assertEqual(
fields.Date.to_string(sheet.date_end),
"1943-12-31",
"The date end should be 1943-12-31",
)
self.assertEqual(
sheet.location_id.id,
self.location.id,
"Wrong location",
)
for line in sheet.line_ids:
line.product_uom_qty = 1
self.assertEqual(
line.product_id.id,
self.product_1.id,
"The product does not match in the line",
)
self.assertEqual(
line.location_id.id,
self.location.id,
"The product does not match in the line",
)
sheet.button_validate()
ranges = self.env["date.range"].search(
[("type_id", "=", self.drt_monthly.id)],
)
estimates = self.env["stock.demand.estimate"].search(
[("date_range_id", "in", ranges.ids)]
)
self.assertEqual(
len(estimates),
12,
"There should be 12 estimate records.",
)
for estimate in estimates:
self.assertEqual(
estimate.product_id.id,
self.product_1.id,
"The product does not match in the estimate",
)
self.assertEqual(
estimate.location_id.id,
self.location.id,
"The product does not match in the estimate",
)
sheets = self.env["stock.demand.estimate.sheet"].search([])
for sheet in sheets:
sheet.unlink()
wiz = self.env["stock.demand.estimate.wizard"]
wiz = wiz.create(
{
"date_start": "1943-01-01",
"date_end": "1943-12-31",
"location_id": self.location.id,
"date_range_type_id": self.drt_monthly.id,
"product_ids": [(6, 0, [self.product_1.id])],
}
)
wiz.create_sheet()
sheets = self.env["stock.demand.estimate.sheet"].search([])
for sheet in sheets:
for line in sheet.line_ids:
self.assertEqual(
line.product_uom_qty,
1,
"The quantity should be 1",
)
def test_02_invalid_dates(self):
wiz = self.env["stock.demand.estimate.wizard"]
with self.assertRaises(ValidationError):
wiz.create(
{
"date_start": "1943-12-31",
"date_end": "1943-01-01",
"location_id": self.location.id,
"date_range_type_id": self.drt_monthly.id,
"product_ids": [(6, 0, [self.product_1.id])],
}
)
def test_03_computed_fields(self):
date_range = self.env["date.range"].search(
[("type_id", "=", self.drt_monthly.id)], limit=1
)
estimate = self.estimate_model.create(
{
"product_id": self.product_1.id,
"location_id": self.location.id,
"date_range_id": date_range.id,
"product_uom_qty": 100.0,
}
)
expected_date_from = date_range.date_start
expected_date_to = date_range.date_end
self.assertEqual(estimate.date_from, expected_date_from)
self.assertEqual(estimate.date_to, expected_date_to)
| 35.706468
| 7,177
|
1,353
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class StockDemandEstimate(models.Model):
_inherit = "stock.demand.estimate"
date_range_id = fields.Many2one(
comodel_name="date.range", string="Estimating Period", ondelete="restrict"
)
@api.depends(
"date_range_id",
"manual_duration",
"manual_date_from",
"manual_date_to",
)
def _compute_dates(self):
date_range_records = self.filtered(lambda r: r.date_range_id)
res = super(StockDemandEstimate, self - date_range_records)._compute_dates()
for rec in date_range_records:
rec.date_from = rec.date_range_id.date_start
rec.date_to = rec.date_range_id.date_end
rec.duration = rec.date_range_id.days
return res
def name_get(self):
date_range_records = self.filtered(lambda r: r.date_range_id)
res = super(StockDemandEstimate, self - date_range_records).name_get()
for rec in date_range_records:
name = "{} - {} - {}".format(
rec.date_range_id.name,
rec.product_id.name,
rec.location_id.name,
)
res.append((rec.id, name))
return res
| 34.692308
| 1,353
|
571
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class DateRange(models.Model):
_inherit = "date.range"
days = fields.Integer(
string="Days between dates",
compute="_compute_days",
readonly=True,
)
@api.depends("date_start", "date_end")
def _compute_days(self):
for rec in self.filtered(lambda x: x.date_start and x.date_end):
rec.days = abs((rec.date_end - rec.date_start).days) + 1
| 30.052632
| 571
|
922
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class StockDemandEstimateSheetLine(models.TransientModel):
_name = "stock.demand.estimate.sheet.line"
_description = "Stock Demand Estimate Sheet Line"
estimate_id = fields.Many2one(comodel_name="stock.demand.estimate")
date_range_id = fields.Many2one(comodel_name="date.range", string="Period")
location_id = fields.Many2one(
comodel_name="stock.location", string="Stock Location"
)
product_id = fields.Many2one(comodel_name="product.product", string="Product")
value_x = fields.Char(string="Period Name")
value_y = fields.Char(string="Product Name")
product_uom = fields.Many2one(comodel_name="uom.uom", string="Unit of measure")
product_uom_qty = fields.Float(string="Quantity", digits="Product UoM")
| 46.1
| 922
|
5,532
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.osv import expression
class StockDemandEstimateSheet(models.TransientModel):
_name = "stock.demand.estimate.sheet"
_description = "Stock Demand Estimate Sheet"
date_start = fields.Date(
string="Date From",
readonly=True,
)
date_end = fields.Date(
string="Date to",
readonly=True,
)
date_range_type_id = fields.Many2one(
string="Date Range Type",
comodel_name="date.range.type",
readonly=True,
)
location_id = fields.Many2one(
comodel_name="stock.location",
string="Location",
readonly=True,
)
line_ids = fields.Many2many(
string="Estimates",
comodel_name="stock.demand.estimate.sheet.line",
relation="stock_demand_estimate_line_rel",
)
product_ids = fields.Many2many(
string="Products",
comodel_name="product.product",
)
@api.onchange(
"date_start",
"date_end",
"date_range_type_id",
)
def _onchange_dates(self):
for sheet in self:
if not all([sheet.date_start, sheet.date_end, sheet.date_range_type_id]):
return
ranges = sheet._get_ranges()
if not ranges:
raise UserError(_("There is no ranges created."))
estimates = self.env["stock.demand.estimate"].search(
[
("product_id", "in", sheet.product_ids.ids),
("date_range_id", "in", ranges.ids),
("location_id", "=", sheet.location_id.id),
]
)
lines = []
for product in sheet.product_ids:
for _range in ranges:
estimate = estimates.filtered(
lambda x: (
x.date_range_id == _range and x.product_id == product
)
)
if estimate:
uom_id = fields.first(estimate).product_uom.id
uom_qty = estimate[0].product_uom_qty
estimate_id = estimate[0].id
else:
uom_id = product.uom_id.id
uom_qty = 0.0
estimate_id = None
lines.append(
(
0,
0,
sheet._get_default_estimate_line(
_range,
product,
uom_id,
uom_qty,
estimate_id=estimate_id,
),
)
)
sheet.line_ids = lines
def _get_ranges(self):
domain_1 = [
"&",
("type_id", "=", self.date_range_type_id.id),
"|",
"&",
("date_start", ">=", self.date_start),
("date_start", "<=", self.date_end),
"&",
("date_end", ">=", self.date_start),
("date_end", "<=", self.date_end),
]
domain_2 = [
"&",
("type_id", "=", self.date_range_type_id.id),
"&",
("date_start", "<=", self.date_start),
("date_end", ">=", self.date_start),
]
domain = expression.OR([domain_1, domain_2])
ranges = self.env["date.range"].search(domain)
return ranges
def _get_default_estimate_line(
self, _range, product, uom_id, uom_qty, estimate_id=None
):
name_y = "{} - {}".format(product.name, product.uom_id.name)
if product.default_code:
name_y += "[{}] {}".format(product.default_code, name_y)
values = {
"value_x": _range.name,
"value_y": name_y,
"date_range_id": _range.id,
"product_id": product.id,
"product_uom": uom_id,
"product_uom_qty": uom_qty,
"location_id": self.location_id.id,
"estimate_id": estimate_id,
}
return values
@api.model
def _prepare_estimate_data(self, line):
return {
"date_range_id": line.date_range_id.id,
"product_id": line.product_id.id,
"location_id": line.location_id.id,
"product_uom_qty": line.product_uom_qty,
"product_uom": line.product_id.uom_id.id,
}
def button_validate(self):
res = []
for line in self.line_ids:
if line.estimate_id:
line.estimate_id.product_uom_qty = line.product_uom_qty
res.append(line.estimate_id.id)
else:
data = self._prepare_estimate_data(line)
estimate = self.env["stock.demand.estimate"].create(data)
res.append(estimate.id)
res = {
"domain": [("id", "in", res)],
"name": _("Stock Demand Estimates"),
"src_model": "stock.demand.estimate.wizard",
"view_type": "form",
"view_mode": "tree",
"res_model": "stock.demand.estimate",
"type": "ir.actions.act_window",
}
return res
| 34.360248
| 5,532
|
2,858
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError
class DemandEstimateWizard(models.TransientModel):
_name = "stock.demand.estimate.wizard"
_description = "Stock Demand Estimate Wizard"
date_start = fields.Date(
string="Date From",
required=True,
)
date_end = fields.Date(
string="Date To",
required=True,
)
date_range_type_id = fields.Many2one(
string="Date Range Type",
comodel_name="date.range.type",
required=True,
)
location_id = fields.Many2one(
comodel_name="stock.location",
string="Location",
required=True,
)
product_ids = fields.Many2many(
comodel_name="product.product",
string="Products",
)
@api.onchange("date_range_type_id")
def _onchange_date_range_type_id(self):
if self.date_range_type_id.company_id:
return {
"domain": {
"location_id": [
("company_id", "=", self.date_range_type_id.company_id.id)
]
}
}
return {}
@api.constrains("date_start", "date_end")
def _check_start_end_dates(self):
self.ensure_one()
if self.date_start > self.date_end:
raise ValidationError(
_("The start date cannot be later than the end date.")
)
def _prepare_demand_estimate_sheet(self):
self.ensure_one()
return {
"date_start": self.date_start,
"date_end": self.date_end,
"date_range_type_id": self.date_range_type_id.id,
"location_id": self.location_id.id,
}
def create_sheet(self):
self.ensure_one()
if not self.product_ids:
raise UserError(_("You must select at least one product."))
# 2d matrix widget need real records to work
sheet = self.env["stock.demand.estimate.sheet"].create(
{
"date_start": self.date_start,
"date_end": self.date_end,
"date_range_type_id": self.date_range_type_id.id,
"location_id": self.location_id.id,
"product_ids": [(6, 0, self.product_ids.ids)],
}
)
sheet._onchange_dates()
res = {
"name": _("Estimate Sheet"),
"src_model": "stock.demand.estimate.wizard",
"view_type": "form",
"view_mode": "form",
"target": "new",
"res_model": "stock.demand.estimate.sheet",
"res_id": sheet.id,
"type": "ir.actions.act_window",
}
return res
| 31.406593
| 2,858
|
641
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Scrap Reason Code",
"version": "15.0.1.1.0",
"license": "AGPL-3",
"summary": "Reason code for scrapping",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management",
"depends": ["stock"],
"data": [
"security/ir.model.access.csv",
"views/reason_code_view.xml",
"views/stock_scrap_views.xml",
"views/stock_move_views.xml",
],
"maintainers": ["bodedra"],
"installable": True,
}
| 32.05
| 641
|
8,646
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2019 IBM Corp.
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
class StockScrap(TransactionCase):
def setUp(self):
super(StockScrap, self).setUp()
self.stock_location = self.env.ref("stock.stock_location_stock")
self.customer_location = self.env.ref("stock.stock_location_customers")
self.categ_1 = self.env.ref("product.product_category_all")
self.categ_2 = self.env["product.category"].create({"name": "Test category"})
stock_location_locations_virtual = self.env["stock.location"].create(
{"name": "Virtual Locations", "usage": "view", "posz": 1}
)
self.scrapped_location = self.env["stock.location"].create(
{
"name": "Scrapped",
"location_id": stock_location_locations_virtual.id,
"scrap_location": True,
"usage": "inventory",
}
)
self.scrap_product = self.env["product.product"].create(
{
"name": "Scrap Product A",
"type": "product",
"categ_id": self.categ_1.id,
}
)
self.scrap_product_2 = self.env["product.product"].create(
{
"name": "Scrap Product A",
"type": "product",
"categ_id": self.categ_2.id,
}
)
self.reason_code = self.env["scrap.reason.code"].create(
{
"name": "DM300",
"description": "Product is damage",
"location_id": self.scrapped_location.id,
}
)
self.reason_code_only_categ_2 = self.env["scrap.reason.code"].create(
{
"name": "Test Code 2",
"description": "Test description",
"product_category_ids": [(6, 0, self.categ_2.ids)],
}
)
self.uom_unit = self.env.ref("uom.product_uom_unit")
def test_scrap_reason_code(self):
"""Scrap the product of a picking. Then modify the
done linked stock move and ensure the scrap quantity is also
updated and verify scrap reason code
"""
self.env["stock.quant"]._update_available_quantity(
self.scrap_product, self.stock_location, 10
)
partner = self.env["res.partner"].create({"name": "BOdedra"})
picking = self.env["stock.picking"].create(
{
"name": "A single picking with one move to scrap",
"location_id": self.stock_location.id,
"location_dest_id": self.customer_location.id,
"partner_id": partner.id,
"picking_type_id": self.env.ref("stock.picking_type_out").id,
}
)
move1 = self.env["stock.move"].create(
{
"name": "A move to confirm and scrap its product",
"location_id": self.stock_location.id,
"location_dest_id": self.customer_location.id,
"product_id": self.scrap_product.id,
"product_uom": self.uom_unit.id,
"product_uom_qty": 1.0,
"picking_id": picking.id,
}
)
move1._action_confirm()
self.assertEqual(move1.state, "assigned")
scrap = self.env["stock.scrap"].create(
{
"product_id": self.scrap_product.id,
"product_uom_id": self.scrap_product.uom_id.id,
"scrap_qty": 5,
"picking_id": picking.id,
"reason_code_id": self.reason_code.id,
}
)
scrap._onchange_reason_code_id()
scrap.do_scrap()
self.assertEqual(len(picking.move_lines), 2)
scrapped_move = picking.move_lines.filtered(lambda m: m.state == "done")
self.assertTrue(scrapped_move, "No scrapped move created.")
self.assertEqual(
scrapped_move.scrap_ids.ids, [scrap.id], "Wrong scrap linked to the move."
)
self.assertEqual(
scrap.scrap_qty,
5,
"Scrap quantity has been modified and is not " "correct anymore.",
)
move = scrap.move_id
self.assertEqual(move.reason_code_id.id, self.reason_code.id)
scrapped_move.quantity_done = 8
self.assertEqual(scrap.scrap_qty, 8, "Scrap quantity is not updated.")
def test_scrap_reason_code_write(self):
"""Scrap the product of a picking2. Then modify the
done linked stock move and ensure the scrap quantity is also
updated and verify scrap reason code
"""
self.env["stock.quant"]._update_available_quantity(
self.scrap_product, self.stock_location, 10
)
partner2 = self.env["res.partner"].create({"name": "BOdedra 2"})
picking2 = self.env["stock.picking"].create(
{
"name": "A single picking with one move to scrap 2",
"location_id": self.stock_location.id,
"location_dest_id": self.customer_location.id,
"partner_id": partner2.id,
"picking_type_id": self.env.ref("stock.picking_type_out").id,
}
)
move2 = self.env["stock.move"].create(
{
"name": "A move to confirm and scrap its product",
"location_id": self.stock_location.id,
"location_dest_id": self.customer_location.id,
"product_id": self.scrap_product.id,
"product_uom": self.uom_unit.id,
"product_uom_qty": 1.0,
"picking_id": picking2.id,
}
)
move2._action_confirm()
self.assertEqual(move2.state, "assigned")
scrap2 = self.env["stock.scrap"].create(
{
"product_id": self.scrap_product.id,
"product_uom_id": self.scrap_product.uom_id.id,
"scrap_qty": 5,
"picking_id": picking2.id,
}
)
scrap2.write(
{
"reason_code_id": self.reason_code.id,
}
)
scrap2._onchange_reason_code_id()
scrap2.do_scrap()
self.assertEqual(len(picking2.move_lines), 2)
scrapped_move = picking2.move_lines.filtered(lambda m: m.state == "done")
self.assertTrue(scrapped_move, "No scrapped move created.")
self.assertEqual(
scrapped_move.scrap_ids.ids, [scrap2.id], "Wrong scrap linked to the move."
)
self.assertEqual(
scrap2.scrap_qty,
5,
"Scrap quantity has been modified and is not " "correct anymore.",
)
move = scrap2.move_id
self.assertEqual(move.reason_code_id.id, self.reason_code.id)
scrapped_move.quantity_done = 8
self.assertEqual(scrap2.scrap_qty, 8, "Scrap quantity is not updated.")
def test_allowed_reason_codes(self):
with self.assertRaises(ValidationError):
self.env["stock.scrap"].create(
{
"product_id": self.scrap_product.id,
"product_uom_id": self.scrap_product_2.uom_id.id,
"scrap_qty": 5,
"reason_code_id": self.reason_code_only_categ_2.id,
}
)
scrap = self.env["stock.scrap"].create(
{
"product_id": self.scrap_product.id,
"product_uom_id": self.scrap_product.uom_id.id,
"scrap_qty": 5,
"reason_code_id": self.reason_code.id,
}
)
self.assertEqual(scrap.allowed_reason_code_ids, self.reason_code)
with self.assertRaises(ValidationError):
scrap.write({"reason_code_id": self.reason_code_only_categ_2.id})
scrap = self.env["stock.scrap"].create(
{
"product_id": self.scrap_product_2.id,
"product_uom_id": self.scrap_product_2.uom_id.id,
"scrap_qty": 5,
"reason_code_id": self.reason_code_only_categ_2.id,
}
)
with self.assertRaises(ValidationError):
scrap.write({"product_id": self.scrap_product.id})
self.assertEqual(
scrap.allowed_reason_code_ids,
(self.reason_code + self.reason_code_only_categ_2),
)
scrap.write({"reason_code_id": self.reason_code.id})
| 39.3
| 8,646
|
889
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2019 IBM Corp.
# Copyright (C) 2019 Open Source Integrators
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ScrapReasonCode(models.Model):
_name = "scrap.reason.code"
_description = "Reason Code"
name = fields.Char("Code", required=True)
description = fields.Text()
location_id = fields.Many2one(
"stock.location",
string="Scrap Location",
domain="[('scrap_location', '=', True)]",
)
product_category_ids = fields.Many2many(
string="Allowed Product Categories",
comodel_name="product.category",
help="Indicate the cateogories of products that can use this reason code "
"when doing a scrap. If left empy, this reason code can be used "
"with any product.",
)
| 34.192308
| 889
|
2,759
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2019 IBM Corp.
# Copyright (C) 2019 Open Source Integrators
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class StockScrap(models.Model):
_inherit = "stock.scrap"
reason_code_id = fields.Many2one(
comodel_name="scrap.reason.code",
string="Reason Code",
states={"done": [("readonly", True)]},
domain="[('id', 'in', allowed_reason_code_ids)]",
)
allowed_reason_code_ids = fields.Many2many(
comodel_name="scrap.reason.code",
compute="_compute_allowed_reason_code_ids",
)
scrap_location_id = fields.Many2one(readonly=True)
@api.depends("product_id", "product_id.categ_id")
def _compute_allowed_reason_code_ids(self):
for rec in self:
codes = self.env["scrap.reason.code"]
if rec.product_id:
codes = codes.search(
[
"|",
("product_category_ids", "=", False),
("product_category_ids", "in", rec.product_id.categ_id.id),
]
)
rec.allowed_reason_code_ids = codes
@api.constrains("reason_code_id", "product_id")
def _check_reason_code_id(self):
for rec in self:
if (
rec.reason_code_id
and rec.reason_code_id not in rec.allowed_reason_code_ids
):
raise ValidationError(
_(
"The selected reason code is not allowed for this product category."
)
)
def _prepare_move_values(self):
res = super(StockScrap, self)._prepare_move_values()
res["reason_code_id"] = self.reason_code_id.id
return res
@api.onchange("reason_code_id")
def _onchange_reason_code_id(self):
if self.reason_code_id.location_id:
self.scrap_location_id = self.reason_code_id.location_id
def _update_scrap_reason_code_location(self, vals):
if "reason_code_id" in vals:
location_id = (
self.env["scrap.reason.code"]
.browse(vals.get("reason_code_id"))
.location_id.id
)
if location_id:
vals.update({"scrap_location_id": location_id})
def write(self, vals):
self._update_scrap_reason_code_location(vals)
return super(StockScrap, self).write(vals)
@api.model
def create(self, vals):
self._update_scrap_reason_code_location(vals)
return super(StockScrap, self).create(vals)
| 34.924051
| 2,759
|
315
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2019 IBM Corp.
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class StockMove(models.Model):
_inherit = "stock.move"
reason_code_id = fields.Many2one("scrap.reason.code", string="Reason code")
| 28.636364
| 315
|
522
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Stock Free Quantity",
"version": "15.0.1.0.1",
"author": "akretion,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"development_status": "Production/Stable",
"category": "Warehouse",
"depends": ["stock"],
"license": "AGPL-3",
"data": [
"views/product_template_view.xml",
"views/product_product_view.xml",
],
"installable": True,
}
| 30.705882
| 522
|
1,429
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo.tests.common import TransactionCase
class TestTemplateFreeQty(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.template_with_variant = cls.env.ref(
"product.product_product_11_product_template"
)
cls.template_with_no_variant = cls.env.ref(
"product.product_product_10_product_template"
)
def test_template_free_qty(self):
# template has 2 variants with 26 and 30 free qty, template should have 56
self.assertEqual(self.template_with_variant.free_qty, 56)
self.assertEqual(
self.template_with_no_variant.free_qty,
self.template_with_no_variant.product_variant_ids.free_qty,
)
def test_search_template_free_qty(self):
template_with_free_qty_ids = (
self.env["product.template"].search([("free_qty", ">", 0)]).ids
)
self.assertIn(self.template_with_variant.id, template_with_free_qty_ids)
self.assertIn(self.template_with_no_variant.id, template_with_free_qty_ids)
template_with_no_free_qty = self.env.ref(
"product.product_product_22_product_template"
)
self.assertNotIn(template_with_no_free_qty.id, template_with_free_qty_ids)
| 40.828571
| 1,429
|
1,094
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
def _compute_quantities_dict(self):
prod_available = super()._compute_quantities_dict()
for template in self:
free_qty = 0
for p in template.with_context(active_test=False).product_variant_ids:
free_qty += p.free_qty
prod_available[template.id]["free_qty"] = free_qty
return prod_available
def _compute_quantities(self):
super()._compute_quantities()
res = self._compute_quantities_dict()
for template in self:
template.free_qty = res[template.id]["free_qty"]
return
def _search_free_qty(self, operator, value):
return [("product_variant_ids.free_qty", operator, value)]
free_qty = fields.Float(
"Free Quantity",
compute="_compute_quantities",
search="_search_free_qty",
compute_sudo=False,
digits="Product Unit of Measure",
)
| 32.176471
| 1,094
|
1,565
|
py
|
PYTHON
|
15.0
|
# Copyright 2018-22 Creu Blanca
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Stock Request kanban",
"version": "15.0.1.1.1",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Creu Blanca, ForgeFlow, Odoo Community Association (OCA)",
"license": "LGPL-3",
"summary": "Adds a stock request order, and takes stock requests as lines",
"depends": ["stock_request", "barcodes"],
"data": [
"data/stock_request_sequence_data.xml",
"report/report_paper_format.xml",
"wizard/wizard_stock_inventory_kanban_views.xml",
"wizard/wizard_stock_request_kanban_views.xml",
"wizard/wizard_stock_request_order_kanban_views.xml",
"views/stock_request_order_views.xml",
"views/stock_request_kanban_views.xml",
"views/stock_inventory_kanban_views.xml",
"views/stock_request_menu.xml",
"views/stock_request_views.xml",
"views/product_views.xml",
"report/stock_request_kanban_templates.xml",
"security/ir.model.access.csv",
],
"assets": {
"web.assets_backend": [
"stock_request_kanban/static/src/js/stock_request_kanban_scan_controller.esm.js",
"stock_request_kanban/static/src/js/stock_request_kanban_scan_view.esm.js",
],
"web.assets_qweb": [
"stock_request_kanban/static/src/xml/stock_request_kanban_scan.xml",
],
},
"installable": True,
"application": False,
}
| 40.128205
| 1,565
|
524
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Creu Blanca
# Copyright 2017-2020 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from reportlab.graphics.barcode import getCodes
from odoo.tests.common import TransactionCase
class TestBaseKanban(TransactionCase):
def pass_code(self, wizard, code):
bcc = getCodes()[self.env["stock.request.kanban"].get_barcode_format()](
value=code
)
bcc.validate()
bcc.encode()
wizard.on_barcode_scanned(bcc.encoded[1:-1])
| 30.823529
| 524
|
7,717
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Creu Blanca
# Copyright 2017-2020 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo.exceptions import ValidationError
from .base_test import TestBaseKanban
class TestKanban(TestBaseKanban):
def setUp(self):
super().setUp()
self.main_company = self.env.ref("base.main_company")
self.warehouse = self.env.ref("stock.warehouse0")
self.categ_unit = self.env.ref("uom.product_uom_categ_unit")
# common data
self.company_2 = self.env["res.company"].create({"name": "Comp2"})
self.wh2 = self.env["stock.warehouse"].search(
[("company_id", "=", self.company_2.id)], limit=1
)
self.wh3 = self.env["stock.warehouse"].create(
{
"name": "Warehouse TEst",
"code": "WH-TEST",
"company_id": self.main_company.id,
}
)
self.ressuply_loc = self.env["stock.location"].create(
{"name": "Ressuply", "location_id": self.warehouse.view_location_id.id}
)
self.route = self.env["stock.location.route"].create(
{
"name": "Transfer",
"product_categ_selectable": False,
"product_selectable": True,
"company_id": self.main_company.id,
"sequence": 10,
}
)
self.product = self.env["product.product"].create(
{"name": "Product", "route_ids": [(4, self.route.id)], "company_id": False}
)
self.uom_dozen = self.env["uom.uom"].create(
{
"name": "Test-DozenA",
"category_id": self.categ_unit.id,
"factor_inv": 12,
"uom_type": "bigger",
"rounding": 0.001,
}
)
self.env["stock.rule"].create(
{
"name": "Transfer",
"route_id": self.route.id,
"location_src_id": self.ressuply_loc.id,
"location_id": self.warehouse.lot_stock_id.id,
"action": "pull_push",
"picking_type_id": self.warehouse.int_type_id.id,
"procure_method": "make_to_stock",
"warehouse_id": self.warehouse.id,
"company_id": self.main_company.id,
}
)
self.env["ir.config_parameter"].set_param("stock_request_kanban.crc", "1")
def test_onchanges(self):
kanban = self.env["stock.request.kanban"].new({})
kanban.product_id = self.product
kanban.onchange_product_id()
kanban.company_id = self.main_company
kanban.onchange_company_id()
self.assertTrue(kanban.warehouse_id)
kanban.warehouse_id = self.wh2
kanban.onchange_warehouse_id()
self.assertEqual(kanban.company_id, self.company_2)
kanban.location_id = self.warehouse.view_location_id
kanban.onchange_location_id()
self.assertEqual(kanban.company_id, self.main_company)
self.assertEqual(kanban.warehouse_id, self.warehouse)
def test_create(self):
kanban = self.env["stock.request.kanban"].new({})
kanban.product_id = self.product
kanban.onchange_product_id()
kanban.product_uom_qty = 1
kanban = kanban.create(kanban._convert_to_write(kanban._cache))
self.assertTrue(kanban.company_id)
self.assertIn(self.route, kanban.route_ids)
def test_order_barcodes(self):
kanban_1 = self.env["stock.request.kanban"].create(
{
"product_id": self.product.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 1,
}
)
kanban_2 = self.env["stock.request.kanban"].create(
{
"product_id": self.product.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 1,
}
)
kanban_3 = self.env["stock.request.kanban"].create(
{
"product_id": self.product.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 1,
"company_id": self.main_company.id,
"warehouse_id": self.wh3.id,
"location_id": self.wh3.lot_stock_id.id,
}
)
order = self.env["stock.request.order"].create(
{
"company_id": self.main_company.id,
"warehouse_id": self.warehouse.id,
"location_id": self.warehouse.lot_stock_id.id,
}
)
wizard = (
self.env["wizard.stock.request.order.kanban"]
.with_context(default_order_id=order.id)
.create({})
)
with self.assertRaises(ValidationError):
wizard.on_barcode_scanned(kanban_1.name)
self.pass_code(wizard, kanban_1.name)
self.assertEqual(wizard.status_state, 0)
self.assertTrue(
order.stock_request_ids.filtered(lambda r: r.kanban_id == kanban_1)
)
self.pass_code(wizard, kanban_2.name)
self.assertTrue(
order.stock_request_ids.filtered(lambda r: r.kanban_id == kanban_2)
)
self.assertEqual(wizard.status_state, 0)
self.pass_code(wizard, kanban_1.name)
self.assertEqual(wizard.status_state, 1)
self.pass_code(wizard, kanban_2.name + kanban_1.name)
self.assertEqual(wizard.status_state, 1)
with self.assertRaises(ValidationError):
self.pass_code(wizard, kanban_3.name)
def test_barcodes(self):
kanban_1 = self.env["stock.request.kanban"].create(
{
"product_id": self.product.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 1,
}
)
kanban_2 = self.env["stock.request.kanban"].create(
{
"product_id": self.product.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 1,
}
)
kanban_3 = self.env["stock.request.kanban"].create(
{
"product_id": self.product.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 1,
}
)
wizard = self.env["wizard.stock.request.kanban"].with_context().create({})
with self.assertRaises(ValidationError):
wizard.on_barcode_scanned(kanban_1.name)
self.assertFalse(
self.env["stock.request"].search([("kanban_id", "=", kanban_1.id)])
)
self.pass_code(wizard, kanban_1.name)
self.assertEqual(wizard.status_state, 0)
self.assertTrue(
self.env["stock.request"].search([("kanban_id", "=", kanban_1.id)])
)
self.assertFalse(
self.env["stock.request"].search([("kanban_id", "=", kanban_2.id)])
)
self.pass_code(wizard, kanban_2.name)
self.assertTrue(
self.env["stock.request"].search([("kanban_id", "=", kanban_2.id)])
)
with self.assertRaises(ValidationError):
wizard.on_barcode_scanned(kanban_3.name)
self.assertFalse(
self.env["stock.request"].search([("kanban_id", "=", kanban_3.id)])
)
self.env["ir.config_parameter"].set_param("stock_request_kanban.crc", "0")
wizard.on_barcode_scanned(kanban_3.name)
self.assertEqual(wizard.status_state, 0)
self.assertTrue(
self.env["stock.request"].search([("kanban_id", "=", kanban_3.id)])
)
| 38.585
| 7,717
|
4,521
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Creu Blanca
# Copyright 2017-2020 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from .base_test import TestBaseKanban
class TestKanban(TestBaseKanban):
def setUp(self):
super().setUp()
self.main_company = self.env.ref("base.main_company")
self.route = self.env["stock.location.route"].create(
{
"name": "Transfer",
"product_categ_selectable": False,
"product_selectable": True,
"company_id": self.main_company.id,
"sequence": 10,
}
)
self.product = self.env["product.product"].create(
{"name": "Product", "route_ids": [(4, self.route.id)], "company_id": False}
)
self.product_2 = self.env["product.product"].create(
{
"name": "Product 2",
"route_ids": [(4, self.route.id)],
"company_id": False,
}
)
self.kanban_1 = self.env["stock.request.kanban"].create(
{
"product_id": self.product.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 1,
}
)
self.kanban_2 = self.env["stock.request.kanban"].create(
{
"product_id": self.product.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 1,
}
)
self.kanban_3 = self.env["stock.request.kanban"].create(
{
"product_id": self.product_2.id,
"product_uom_id": self.product.uom_id.id,
"product_uom_qty": 1,
}
)
def test_inventory_warehouse(self):
inventory = self.env["stock.inventory.kanban"].create(
{"warehouse_ids": [(4, self.kanban_1.warehouse_id.id)]}
)
inventory.start_inventory()
self.assertIn(self.kanban_1, inventory.kanban_ids)
self.assertIn(self.kanban_1, inventory.missing_kanban_ids)
def test_inventory_location(self):
inventory = self.env["stock.inventory.kanban"].create(
{"location_ids": [(4, self.kanban_1.location_id.id)]}
)
inventory.start_inventory()
self.assertIn(self.kanban_1, inventory.kanban_ids)
self.assertIn(self.kanban_1, inventory.missing_kanban_ids)
def test_inventory_product(self):
inventory = self.env["stock.inventory.kanban"].create(
{"product_ids": [(4, self.product.id)]}
)
inventory.start_inventory()
self.assertIn(self.kanban_1, inventory.kanban_ids)
self.assertNotIn(self.kanban_3, inventory.kanban_ids)
self.assertIn(self.kanban_1, inventory.missing_kanban_ids)
self.assertEqual(inventory.state, "in_progress")
wizard = (
self.env["wizard.stock.inventory.kanban"]
.with_context(default_inventory_kanban_id=inventory.id)
.create({})
)
self.pass_code(wizard, self.kanban_3.name)
self.assertEqual(wizard.status_state, 1)
self.pass_code(wizard, self.kanban_1.name)
self.assertEqual(wizard.status_state, 0)
self.assertNotIn(self.kanban_1, inventory.missing_kanban_ids)
self.assertIn(self.kanban_1, inventory.scanned_kanban_ids)
self.pass_code(wizard, self.kanban_1.name)
self.assertEqual(wizard.status_state, 1)
self.assertNotIn(self.kanban_1, inventory.missing_kanban_ids)
self.assertIn(self.kanban_1, inventory.scanned_kanban_ids)
inventory.finish_inventory()
self.assertEqual(inventory.state, "finished")
inventory.close_inventory()
self.assertEqual(inventory.state, "closed")
def test_cancel_inventory(self):
inventory = self.env["stock.inventory.kanban"].create(
{"product_ids": [(4, self.product.id)]}
)
inventory.start_inventory()
self.assertIn(self.kanban_1, inventory.kanban_ids)
self.assertNotIn(self.kanban_3, inventory.kanban_ids)
self.assertIn(self.kanban_1, inventory.missing_kanban_ids)
self.assertEqual(inventory.state, "in_progress")
inventory.cancel()
self.assertEqual(inventory.state, "cancelled")
inventory.to_draft()
self.assertEqual(inventory.state, "draft")
self.assertFalse(inventory.kanban_ids)
self.assertFalse(inventory.scanned_kanban_ids)
| 40.366071
| 4,521
|
1,836
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Creu Blanca
# Copyright 2017-2020 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, fields, models
class WizardStockRequestKanban(models.TransientModel):
_name = "wizard.stock.request.kanban"
_description = "Stock Request Kanban Wizard"
_inherit = "wizard.stock.request.kanban.abstract"
stock_request_id = fields.Many2one("stock.request", readonly=True)
def barcode_ending(self):
res = super().barcode_ending()
self.stock_request_id = self.env["stock.request"].create(
self.stock_request_kanban_values()
)
self.stock_request_ending()
self.update_status()
return res
def stock_request_ending(self):
self.stock_request_id.action_confirm()
def update_status(self):
self.update(
{
"status_state": 0,
"status": _(
"Added kanban %(kanban)s for product %(product)s",
kanban=self.stock_request_id.kanban_id.name,
product=self.stock_request_id.product_id.display_name,
),
}
)
def stock_request_kanban_values(self):
return {
"company_id": self.kanban_id.company_id.id,
"procurement_group_id": self.kanban_id.procurement_group_id.id or False,
"location_id": self.kanban_id.location_id.id or False,
"warehouse_id": self.kanban_id.warehouse_id.id or False,
"product_id": self.kanban_id.product_id.id,
"product_uom_id": self.kanban_id.product_uom_id.id or False,
"route_id": self.kanban_id.route_id.id or False,
"product_uom_qty": self.kanban_id.product_uom_qty,
"kanban_id": self.kanban_id.id,
}
| 36.72
| 1,836
|
2,213
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Creu Blanca
# Copyright 2017-2020 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, fields, models
from odoo.exceptions import ValidationError
class WizardStockRequestOrderKanban(models.TransientModel):
_name = "wizard.stock.request.order.kanban"
_description = "Stock Request Order Kanban Wizard"
_inherit = "wizard.stock.request.kanban"
order_id = fields.Many2one("stock.request.order", required=True)
def validate_kanban(self, barcode):
res = super().validate_kanban(barcode)
if self.order_id.stock_request_ids.filtered(
lambda r: r.kanban_id == self.kanban_id
):
self.status = _("Barcode %s is on the order") % barcode
self.status_state = 1
return False
if self.order_id.state != "draft":
raise ValidationError(
_("Lines only can be added on orders with draft state")
)
if not self.order_id.company_id:
self.order_id.company_id = self.kanban_id.company_id
elif self.order_id.company_id != self.kanban_id.company_id:
raise ValidationError(_("Company must be the same"))
if (
self.kanban_id.procurement_group_id
and self.order_id.procurement_group_id
!= self.kanban_id.procurement_group_id
):
raise ValidationError(_("Procurement group must be the same"))
if self.order_id.location_id != self.kanban_id.location_id:
raise ValidationError(_("Location must be the same"))
if self.order_id.warehouse_id != self.kanban_id.warehouse_id:
raise ValidationError(_("Warehouse must be the same"))
return res
def stock_request_kanban_values(self):
res = super().stock_request_kanban_values()
res["order_id"] = (self.order_id.id,)
res["expected_date"] = fields.Datetime.to_string(self.order_id.expected_date)
return res
def stock_request_ending(self):
return
def barcode_ending(self):
res = super().barcode_ending()
self.order_id = self.stock_request_id.order_id
return res
| 39.517857
| 2,213
|
1,447
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Creu Blanca
# Copyright 2017-2020 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, fields, models
class WizardStockRequestKanbanAbstract(models.AbstractModel):
_name = "wizard.stock.request.kanban.abstract"
_description = "Stock Request Kanban Abstract Wizard"
_inherit = "barcodes.barcode_events_mixin"
kanban_id = fields.Many2one("stock.request.kanban", readonly=True)
status = fields.Text(readonly=True, default="Start scanning")
status_state = fields.Integer(default=0, readonly=True)
def on_barcode_scanned(self, barcode):
self.kanban_id = self.env["stock.request.kanban"].search_barcode(barcode)
if not self.kanban_id:
self.status = (
_(
"Barcode %s does not correspond to any "
"Kanban. Try with another barcode or "
"press Close to finish scanning."
)
% barcode
)
self.status_state = 1
return
if self.validate_kanban(barcode):
self.status_state = 0
self.barcode_ending()
return
def barcode_ending(self):
pass
def validate_kanban(self, barcode):
"""
It must return True if the kanban is valid, False otherwise
:param barcode:
:return:
"""
return True
| 32.886364
| 1,447
|
1,247
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Creu Blanca
# Copyright 2017-2020 ForgeFlow, S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, fields, models
class WizardStockInventoryKanban(models.TransientModel):
_name = "wizard.stock.inventory.kanban"
_description = "Stock Inventory Kanban Wizard"
_inherit = "wizard.stock.request.kanban.abstract"
inventory_kanban_id = fields.Many2one("stock.inventory.kanban", readonly=True)
def barcode_ending(self):
res = super().barcode_ending()
self.inventory_kanban_id.write({"scanned_kanban_ids": [(4, self.kanban_id.id)]})
return res
def validate_kanban(self, barcode):
res = super().validate_kanban(barcode)
if not self.inventory_kanban_id.kanban_ids.filtered(
lambda r: r == self.kanban_id
):
self.status = _("Barcode %s is not in the inventory") % barcode
self.status_state = 1
return False
if self.inventory_kanban_id.scanned_kanban_ids.filtered(
lambda r: r == self.kanban_id
):
self.status = _("Barcode %s is already scanned") % barcode
self.status_state = 1
return False
return res
| 36.676471
| 1,247
|
271
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Creu Blanca
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import fields, models
class StockRequest(models.Model):
_inherit = "stock.request"
kanban_id = fields.Many2one("stock.request.kanban", readonly=True)
| 27.1
| 271
|
1,797
|
py
|
PYTHON
|
15.0
|
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
kanban_card_count = fields.Integer(
"# Kanban Cards", compute="_compute_kanban_card_count", compute_sudo=False
)
def _compute_kanban_card_count(self):
for product in self:
count = 0
for variant in product.product_variant_ids:
count += self.env["stock.request.kanban"].search_count(
[("product_id", "=", variant.id)]
)
product.kanban_card_count = count
def action_view_kanban_cards(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock_request_kanban.stock_request_kanban_action"
)
action["context"] = {"default_product_id": self.product_variant_id.id}
action["domain"] = [
("active", "=", True),
("product_template_id", "=", self.id),
]
return action
class ProductProduct(models.Model):
_inherit = "product.product"
kanban_card_count = fields.Integer(
"# Kanban Cards", compute="_compute_kanban_card_count", compute_sudo=False
)
def _compute_kanban_card_count(self):
for product in self:
product.kanban_card_count += self.env["stock.request.kanban"].search_count(
[("product_id", "=", product.id)]
)
def action_view_kanban_cards(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock_request_kanban.stock_request_kanban_action"
)
action["context"] = {"default_product_id": self.id}
action["domain"] = [("active", "=", True), ("product_id", "=", self.id)]
return action
| 33.90566
| 1,797
|
4,679
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Creu Blanca
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
from odoo.osv import expression
class StockInventoryKanban(models.Model):
_name = "stock.inventory.kanban"
_description = "Inventory for Kanban"
_inherit = ["mail.thread", "mail.activity.mixin"]
name = fields.Char(
readonly=True, states={"draft": [("readonly", False)]}, copy=False
)
state = fields.Selection(
[
("draft", "Draft"),
("in_progress", "In progress"),
("finished", "Finished"),
("closed", "Closed"),
("cancelled", "Cancelled"),
],
required=True,
default="draft",
readonly=True,
copy=False,
tracking=True,
)
warehouse_ids = fields.Many2many(
"stock.warehouse",
string="Warehouse",
ondelete="cascade",
readonly=True,
states={"draft": [("readonly", False)]},
)
location_ids = fields.Many2many(
"stock.location",
string="Location",
domain=[("usage", "in", ["internal", "transit"])],
ondelete="cascade",
readonly=True,
states={"draft": [("readonly", False)]},
)
product_ids = fields.Many2many(
"product.product",
string="Products",
domain=[("type", "in", ["product", "consu"])],
ondelete="cascade",
readonly=True,
states={"draft": [("readonly", False)]},
)
kanban_ids = fields.Many2many(
"stock.request.kanban",
relation="stock_inventory_kanban_kanban",
readonly=True,
copy=False,
)
scanned_kanban_ids = fields.Many2many(
"stock.request.kanban",
relation="stock_inventory_kanban_scanned_kanban",
readonly=True,
copy=False,
)
missing_kanban_ids = fields.Many2many(
"stock.request.kanban", readonly=True, compute="_compute_missing_kanban"
)
count_missing_kanbans = fields.Integer(
"Missing Kanbans", readonly=True, compute="_compute_missing_kanban"
)
@api.depends("kanban_ids", "scanned_kanban_ids")
def _compute_missing_kanban(self):
for rec in self:
rec.missing_kanban_ids = rec.kanban_ids.filtered(
lambda r: r.id not in rec.scanned_kanban_ids.ids
)
rec.count_missing_kanbans = len(rec.missing_kanban_ids)
def _get_inventory_kanban_domain(self):
domain = []
if self.warehouse_ids:
domain = expression.AND(
(domain, [("warehouse_id", "in", self.warehouse_ids.ids)])
)
if self.product_ids:
domain = expression.AND(
(domain, [("product_id", "in", self.product_ids.ids)])
)
if self.location_ids:
domain = expression.AND(
(domain, [("location_id", "in", self.location_ids.ids)])
)
return domain
def _start_inventory_values(self):
return {"state": "in_progress"}
def _finish_inventory_values(self):
return {"state": "finished"}
def _close_inventory_values(self):
return {"state": "closed"}
@api.model
def create(self, vals):
if vals.get("name", "/") == "/":
vals["name"] = self.env["ir.sequence"].next_by_code(
"stock.inventory.kanban"
)
return super().create(vals)
def calculate_kanbans(self):
for rec in self:
if rec.state == "draft":
rec.kanban_ids = self.env["stock.request.kanban"].search(
rec._get_inventory_kanban_domain()
)
def start_inventory(self):
self.calculate_kanbans()
self.write(self._start_inventory_values())
def finish_inventory(self):
self.write(self._finish_inventory_values())
def close_inventory(self):
self.write(self._close_inventory_values())
def print_missing_kanbans(self):
"""Print the missing kanban cards in order to restore them"""
self.ensure_one()
return self.env.ref("stock_request_kanban.action_report_kanban").report_action(
self.missing_kanban_ids
)
def _cancel_inventory_values(self):
return {"state": "cancelled"}
def cancel(self):
self.write(self._cancel_inventory_values())
def _to_draft_inventory_values(self):
return {
"state": "draft",
"kanban_ids": [(5, 0)],
"scanned_kanban_ids": [(5, 0)],
}
def to_draft(self):
self.write(self._to_draft_inventory_values())
| 30.782895
| 4,679
|
1,881
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Creu Blanca
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from reportlab.graphics.barcode import getCodes
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class StockRequestKanban(models.Model):
_name = "stock.request.kanban"
_description = "Stock Request Kanban"
_inherit = "stock.request.abstract"
active = fields.Boolean(default=True)
product_template_id = fields.Many2one(related="product_id.product_tmpl_id")
@api.model
def create(self, vals):
if vals.get("name", "/") == "/":
vals["name"] = self.env["ir.sequence"].next_by_code("stock.request.kanban")
return super().create(vals)
@api.model
def get_barcode_format(self):
return (
self.env["ir.config_parameter"]
.sudo()
.get_param("stock_request_kanban.barcode_format", default="Standard39")
)
@api.model
def _recompute_barcode(self, barcode):
if (
self.env["ir.config_parameter"]
.sudo()
.get_param("stock_request_kanban.crc", default="1")
== "0"
):
return barcode
if (
self.env["ir.config_parameter"]
.sudo()
.get_param("stock_request_kanban.ignore_crc", default="0")
== "0"
):
bcc = getCodes()[self.get_barcode_format()](value=barcode[:-1])
bcc.validate()
bcc.encode()
if bcc.encoded[1:-1] != barcode:
raise ValidationError(_("CRC is not valid"))
return barcode[:-1]
@api.model
def search_barcode(self, barcode):
recomputed_barcode = self._recompute_barcode(barcode)
return self.env["stock.request.kanban"].search(
[("name", "ilike", recomputed_barcode)]
)
| 31.881356
| 1,881
|
805
|
py
|
PYTHON
|
15.0
|
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
# Copyright 2019-2023 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Stock Change Quantity Reason",
"summary": """
Stock Quantity Change Reason """,
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"depends": ["stock"],
"data": [
"security/ir.model.access.csv",
"security/stock_security.xml",
"views/base_config_view.xml",
"views/stock_move_line_view.xml",
"views/stock_quant_reason_view.xml",
"views/stock_quant_view.xml",
],
"installable": True,
}
| 35
| 805
|
654
|
py
|
PYTHON
|
15.0
|
# Copyright 2023 ForgeFlow <http://www.forgeflow.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade
def fill_required_reason(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE stock_quant_reason sqr
SET name = '???'
WHERE name IS NULL""",
)
@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_tables(
env.cr, [("stock_inventory_line_reason", "stock_quant_reason")]
)
openupgrade.rename_models(
env.cr, [("stock.inventory.line.reason", "stock.quant.reason")]
)
fill_required_reason(env)
| 26.16
| 654
|
1,731
|
py
|
PYTHON
|
15.0
|
# Copyright 2023 ForgeFlow <http://www.forgeflow.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade
def fill_stock_quant_reason(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE stock_move_line sml
SET reason = sil.reason
FROM stock_inventory_line sil
JOIN stock_inventory si ON sil.inventory_id = si.id
JOIN stock_location sl ON sil.location_id = sl.id
JOIN stock_move sm ON sm.inventory_id = si.id
WHERE sil.reason IS NOT NULL AND sml.move_id = sm.id
AND sml.location_id = sl.id
AND sl.usage in ('internal', 'transit')
AND si.state = 'done' AND sml.product_id = sil.product_id
AND ((sil.prod_lot_id IS NULL AND sml.lot_id IS NULL) OR (
sil.prod_lot_id = sml.lot_id))
AND COALESCE(sml.date, sm.date) = COALESCE(
sil.inventory_date, si.date)""",
)
def fill_stock_move_line_preset_reason_id(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE stock_move_line sml
SET preset_reason_id = sm.preset_reason_id
FROM stock_move sm
WHERE sml.move_id = sm.id AND sm.preset_reason_id IS NOT NULL""",
)
def fill_stock_move_line_reason(env):
openupgrade.logged_query(
env.cr,
"""
UPDATE stock_move_line sml
SET reason = COALESCE(sml.reason, sqr.name)
FROM stock_quant_reason sqr
WHERE sml.preset_reason_id = sqr.id""",
)
@openupgrade.migrate()
def migrate(env, version):
fill_stock_quant_reason(env)
fill_stock_move_line_preset_reason_id(env)
fill_stock_move_line_reason(env)
| 32.055556
| 1,731
|
2,740
|
py
|
PYTHON
|
15.0
|
# pylint: disable=import-error,protected-access,too-few-public-methods
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
# Copyright 2019-2023 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestStockQuantityChangeReason(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestStockQuantityChangeReason, cls).setUpClass()
# MODELS
cls.stock_move_line = cls.env["stock.move.line"]
cls.product_product_model = cls.env["product.product"]
cls.product_category_model = cls.env["product.category"]
cls.stock_quant = cls.env["stock.quant"]
cls.preset_reason_id = cls.env["stock.quant.reason"]
cls.stock_location = cls.env.ref("stock.stock_location_stock")
# INSTANCES
cls.category = cls.product_category_model.create({"name": "Physical (test)"})
def _create_product(self, name):
return self.product_product_model.create(
{"name": name, "categ_id": self.category.id, "type": "product"}
)
def _product_change_qty(self, product, location, new_qty):
values = {
"product_id": product.id,
"location_id": location.id,
"inventory_quantity": new_qty,
}
self.stock_quant.with_context(inventory_mode=True).create(values)
def _create_reason(self, name, description=None):
return self.preset_reason_id.create({"name": name, "description": description})
def test_inventory_adjustment_onchange_reason_preset_reason(self):
"""Check that adding a reason or a preset reason explode to lines"""
product2 = self._create_product("product_product_2")
self._product_change_qty(product2, self.stock_location, 50)
inventory_quant = self.env["stock.quant"].create(
{
"product_id": product2.id,
"location_id": self.stock_location.id,
"inventory_quantity": 10,
}
)
inventory_quant.user_id = self.env.user.id
inventory_quant.inventory_quantity_set = True
preset_reason_id = self._create_reason("Test 1", "Description Test 1")
inventory_quant.preset_reason_id = preset_reason_id
inventory_quant.action_apply_inventory()
move_line = self.stock_move_line.search(
[("product_id", "=", product2.id), ("preset_reason_id", "!=", False)]
)
self.assertEqual(len(move_line), 1)
self.assertEqual(inventory_quant.preset_reason_id.name, False)
self.assertEqual(move_line.move_id.origin, preset_reason_id.name)
self.assertEqual(move_line.preset_reason_id, preset_reason_id)
| 43.492063
| 2,740
|
353
|
py
|
PYTHON
|
15.0
|
# Copyright 2019-2023 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import fields, models
class StockMoveLine(models.Model):
_inherit = "stock.move.line"
preset_reason_id = fields.Many2one("stock.quant.reason")
reason = fields.Char(help="Type in a reason for the product quantity change")
| 35.3
| 353
|
1,406
|
py
|
PYTHON
|
15.0
|
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class StockQuant(models.Model):
"""Class to inherit model stock.quant"""
_inherit = "stock.quant"
reason = fields.Char(help="Type in a reason for the product quantity change")
preset_reason_id = fields.Many2one("stock.quant.reason")
@api.model
def _get_inventory_fields_write(self):
res = super()._get_inventory_fields_write()
res.extend(["reason", "preset_reason_id"])
return res
def _get_inventory_move_values(self, qty, location_id, location_dest_id, out=False):
"""Function to super _get_inventory_move_values"""
res = super()._get_inventory_move_values(
qty, location_id, location_dest_id, out
)
context = (
self.reason if not self.preset_reason_id else self.preset_reason_id.name
)
line = res["move_line_ids"][0][2]
line["reason"] = context
if res.get("origin"):
res["origin"] = " ,".join([res.get("origin"), context])
else:
res["origin"] = context
if self.preset_reason_id:
line["preset_reason_id"] = self.preset_reason_id.id
self.preset_reason_id = False
if self.reason:
self.reason = False
return res
| 35.15
| 1,406
|
563
|
py
|
PYTHON
|
15.0
|
# Copyright 2019-2023 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class StockQuantReason(models.Model):
_name = "stock.quant.reason"
_description = "Stock Quant Reason"
name = fields.Char("Reason Name", required=True)
description = fields.Text("Reason Description")
active = fields.Boolean(default=True)
_sql_constraints = [
(
"name_unique",
"UNIQUE(name)",
"You cannot have two reason with the same name.",
)
]
| 28.15
| 563
|
547
|
py
|
PYTHON
|
15.0
|
# Copyright 2019-2023 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
group_qty_reason_preset = fields.Boolean(
string="Preset Change Qty Reason",
required=True,
implied_group="stock_change_qty_reason.group_qty_reason_preset",
help="Enable use of predefined Reasons to manage Inventory Adjustments"
"and Product Update Quantities Wizard.",
)
| 36.466667
| 547
|
522
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Stock Location Lockdown",
"summary": "Prevent to add stock on locked locations",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse",
"version": "15.0.1.0.1",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["stock"],
"data": ["views/stock_location.xml"],
}
| 32.625
| 522
|
3,751
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 Akretion France
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import TransactionCase
class TestStockLocationLockdown(TransactionCase):
def setUp(self, *args, **kwargs):
super(TestStockLocationLockdown, self).setUp(*args, **kwargs)
# Create a new stock location with no quants and blocked stock entrance
new_loc = {"name": "location_test", "usage": "internal"}
self.new_stock_location = self.env["stock.location"].create(new_loc)
self.new_stock_location.block_stock_entrance = True
self.supplier_location = self.env.ref("stock.stock_location_suppliers")
self.customer_location = self.env.ref("stock.stock_location_customers")
# Call an existing product and force no Lot/Serial Number tracking
self.product = self.env.ref("product.product_product_27")
self.product.tracking = "none"
# Catch the first quant's stock location
self.stock_location = self.env["stock.quant"].search([])[0].location_id
def test_transfer_stock_in_locked_location(self):
"""
Test to move stock within a location that should not accept
stock entrance.
"""
move_vals = {
"location_id": self.supplier_location.id,
"location_dest_id": self.new_stock_location.id,
"product_id": self.product.id,
"product_uom_qty": self.product.qty_available + 1,
"product_uom": 1,
"name": "test",
"move_line_ids": [
(
0,
0,
{
"product_id": self.product.id,
"product_uom_qty": 0,
"product_uom_id": 1,
"qty_done": self.product.qty_available + 1,
"location_id": self.supplier_location.id,
"location_dest_id": self.new_stock_location.id,
},
)
],
}
stock_move = self.env["stock.move"].create(move_vals)
with self.assertRaises(ValidationError):
stock_move._action_done()
def test_transfer_stock_out_locked_location(self):
"""
Test to move stock out from a location that should not accept
stock removal.
"""
move_vals = {
"location_id": self.new_stock_location.id,
"location_dest_id": self.customer_location.id,
"product_id": self.product.id,
"product_uom_qty": self.product.qty_available + 1,
"product_uom": 1,
"name": "test",
"move_line_ids": [
(
0,
0,
{
"product_id": self.product.id,
"product_uom_qty": 0,
"product_uom_id": 1,
"qty_done": self.product.qty_available + 1,
"location_id": self.supplier_location.id,
"location_dest_id": self.new_stock_location.id,
},
)
],
}
stock_move = self.env["stock.move"].create(move_vals)
with self.assertRaises(ValidationError):
stock_move._action_done()
def test_block_location_with_quants(self):
"""
Test to click on block_stock_entrance checkbox in a location
that should not be blocked because it has already got quants
"""
with self.assertRaises(UserError):
self.stock_location.write({"block_stock_entrance": True})
| 38.670103
| 3,751
|
1,143
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, fields, models
from odoo.exceptions import UserError
class StockLocation(models.Model):
_inherit = "stock.location"
block_stock_entrance = fields.Boolean(
help="if this box is checked, putting stock on this location won't be "
"allowed. Usually used for a virtual location that has "
"childrens."
)
# Raise error if the location that you're trying to block
# has already got quants
def write(self, values):
res = super().write(values)
if "block_stock_entrance" in values and values["block_stock_entrance"]:
# Unlink zero quants before checking
# if there are quants on the location
self.env["stock.quant"]._unlink_zero_quants()
if self.mapped("quant_ids"):
raise UserError(
_(
"It is impossible to prohibit this location from\
receiving products as it already contains some."
)
)
return res
| 34.636364
| 1,143
|
920
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, models
from odoo.exceptions import ValidationError
class StockQuant(models.Model):
_inherit = "stock.quant"
# Raise an error when trying to change a quant
# which corresponding stock location is blocked
@api.constrains("location_id")
def check_location_blocked(self):
for record in self:
if record.location_id.block_stock_entrance:
raise ValidationError(
_(
"The location %(location)s is blocked and can "
"not be used for moving the product %(product)s"
)
% {
"location": record.location_id.display_name,
"product": record.product_id.display_name,
}
)
| 35.384615
| 920
|
544
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product template in putaway strategies",
"summary": "Add product template in putaway strategies from the product view",
"version": "15.0.1.0.1",
"category": "Inventory",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["stock"],
"data": ["views/stock_putaway_rule_views.xml"],
"maintainers": ["kevinkhao", "sebastienbeau"],
}
| 41.846154
| 544
|
4,979
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2020 Tecnativa - Sergio Teruel
# Copyright 2020-2021 Víctor Martínez - Tecnativa
from odoo.tests import common
class TestStockPutawayRule(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.putawayRuleObj = cls.env["stock.putaway.rule"]
ProductTemplate = cls.env["product.template"]
ProductAttribute = cls.env["product.attribute"]
ProductAttributeValue = cls.env["product.attribute.value"]
TemplateAttributeLine = cls.env["product.template.attribute.line"]
# Add a product with variants
cls.template = ProductTemplate.create({"name": "Product test", "type": "consu"})
cls.size_attribute = ProductAttribute.create(
{"name": "Test size", "sequence": 1}
)
cls.size_m = ProductAttributeValue.create(
{"name": "Size M", "attribute_id": cls.size_attribute.id, "sequence": 1}
)
cls.size_l = ProductAttributeValue.create(
{"name": "Size L", "attribute_id": cls.size_attribute.id, "sequence": 2}
)
cls.size_xl = ProductAttributeValue.create(
{"name": "Size XL", "attribute_id": cls.size_attribute.id, "sequence": 3}
)
cls.template_attribute_lines = TemplateAttributeLine.create(
{
"product_tmpl_id": cls.template.id,
"attribute_id": cls.size_attribute.id,
"value_ids": [(6, 0, [cls.size_m.id, cls.size_l.id, cls.size_xl.id])],
}
)
cls.template._create_variant_ids()
cls.view_id = cls.env.ref("stock.stock_putaway_list").id
def _stock_putaway_rule_product(self, location, product):
rule = self.putawayRuleObj.create(
{
"company_id": location.company_id.id,
"product_id": product.id,
"location_in_id": location.id,
"location_out_id": location.id,
}
)
self.assertEqual(rule.location_in_id, location)
self.assertEqual(rule.product_tmpl_id, product.product_tmpl_id)
self.assertEqual(rule.product_id, product)
return rule
def _get_product_rules(self, product):
return self.putawayRuleObj.search(
product.action_view_related_putaway_rules()["domain"]
)
def test_apply_putaway(self):
# Create one strategy line for product template and other with a
# specific variant
location = self.env.ref("stock.stock_location_shop0")
location1 = location.copy(
{"name": "Location test 1", "location_id": location.id}
)
location2 = location.copy(
{"name": "Location test 2", "location_id": location.id}
)
# Create rule according to product_tmpl_id
rule_product = self.putawayRuleObj.create(
{
"company_id": location1.company_id.id,
"product_tmpl_id": self.template.id,
"location_in_id": location1.id,
"location_out_id": location1.id,
}
)
self.assertEqual(rule_product.location_in_id, location1)
self.assertEqual(rule_product.product_tmpl_id, self.template)
self.assertEqual(rule_product.product_id.id, False)
# Create rules related to variants and diferente locations
variant1 = self.template.product_variant_ids[0]
variant2 = self.template.product_variant_ids[1]
variant3 = self.template.product_variant_ids[2]
self._stock_putaway_rule_product(location1, variant1)
self._stock_putaway_rule_product(location2, variant2)
# Create rule according to category
rule_category = self.putawayRuleObj.create(
{
"company_id": location1.company_id.id,
"category_id": self.template.categ_id.id,
"location_in_id": location1.id,
"location_out_id": location1.id,
}
)
self.assertEqual(rule_category.category_id, self.template.categ_id)
self.assertEqual(rule_category.location_in_id, location1)
self.assertEqual(rule_category.product_tmpl_id.id, False)
self.assertEqual(rule_category.product_id.id, False)
# Check rules related
self.assertEqual(len(self._get_product_rules(self.template)), 4)
self.assertEqual(len(self._get_product_rules(variant1)), 2)
self.assertEqual(len(self._get_product_rules(variant2)), 2)
self.assertEqual(len(self._get_product_rules(variant3)), 1)
# Check _get_putaway_strategy
locations = location + location.child_ids
self.assertEqual(locations._get_putaway_strategy(variant1), location1)
self.assertEqual(locations._get_putaway_strategy(variant2), location2)
self.assertEqual(locations._get_putaway_strategy(variant3), location1)
| 45.245455
| 4,977
|
1,616
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2020 Sergio Teruel - Tecnativa
# Copyright 2020 Víctor Martínez - Tecnativa
from odoo import api, fields, models
class StockPutawayRule(models.Model):
_inherit = "stock.putaway.rule"
product_tmpl_id = fields.Many2one(
comodel_name="product.template",
compute="_compute_product_tmpl_id",
store=True,
readonly=False,
ondelete="cascade",
)
@api.depends("product_id")
def _compute_product_tmpl_id(self):
for rec in self:
if rec.product_id:
rec.product_tmpl_id = rec.product_id.product_tmpl_id
else:
params = self.env.context.get("params", {})
if params.get("model", "") == "product.template" and params.get("id"):
rec.product_tmpl_id = params.get("id")
def filtered(self, func):
res = super().filtered(func)
if res or not self.env.context.get("filter_putaway_rule"):
return res
if isinstance(func, str):
name = func
def func(rec):
any(rec.mapped(name))
# populate cache
self.mapped(name)
product = func.__closure__[0].cell_contents
if isinstance(product, str):
return res
if product._name != "product.product":
return res
return self.with_context(filter_putaway_rule=False).filtered(
lambda x: (
x.product_tmpl_id == product.product_tmpl_id and not x.product_id
)
)
| 32.28
| 1,614
|
618
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2020 Tecnativa - Sergio Teruel
from odoo import models
class StockLocation(models.Model):
_inherit = "stock.location"
def _get_putaway_strategy(
self, product, quantity=0, package=None, packaging=None, additional_qty=None
):
return super(
StockLocation, self.with_context(filter_putaway_rule=True)
)._get_putaway_strategy(
product,
quantity=quantity,
package=package,
packaging=packaging,
additional_qty=additional_qty,
)
| 29.428571
| 618
|
572
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2021 Tecnativa - Víctor Martínez
from odoo import models
class ProductTemplate(models.Model):
_inherit = "product.template"
def action_view_related_putaway_rules(self):
self.ensure_one()
domain = [
"|",
"|",
("product_tmpl_id", "=", self.id),
("category_id", "=", self.categ_id.id),
("product_id.product_tmpl_id", "=", self.id),
]
return self._get_action_view_related_putaway_rules(domain)
| 30
| 570
|
482
|
py
|
PYTHON
|
15.0
|
# Copyright 2020-2021 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
"name": "Stock Helpers",
"summary": "Add methods shared between various stock modules",
"version": "15.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Hidden",
"depends": ["stock"],
"data": [],
"installable": True,
"license": "LGPL-3",
}
| 32.133333
| 482
|
1,626
|
py
|
PYTHON
|
15.0
|
# Copyright 2020-2021 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from .common import StockHelperCommonCase
class TestStockLocationIsSublocationOf(StockHelperCommonCase):
def test_is_sublocation_of_equal(self):
self.assertTrue(self.shelf1_loc.is_sublocation_of(self.shelf1_loc))
def test_is_sublocation_of_equal_child_ko(self):
bin_loc = self.env["stock.location"].create(
{"name": "bin", "location_id": self.shelf1_loc.id}
)
self.assertFalse(self.shelf1_loc.is_sublocation_of(bin_loc))
def test_is_sublocation_of_equal_child_sibling(self):
self.assertFalse(self.shelf1_loc.is_sublocation_of(self.shelf2_loc))
def test_is_sublocation_of_any_ok(self):
self.assertTrue(
self.shelf1_loc.is_sublocation_of(self.stock_loc | self.customer_loc)
)
def test_is_sublocation_of_any_ko(self):
self.assertFalse(
self.shelf1_loc.is_sublocation_of(self.supplier_loc | self.customer_loc)
)
def test_is_sublocation_of_all_ok(self):
self.assertTrue(
self.shelf1_loc.is_sublocation_of(
self.stock_loc | self.stock_loc.location_id, func=all
)
)
def test_is_sublocation_of_all_ko(self):
self.assertFalse(
self.shelf1_loc.is_sublocation_of(
self.stock_loc | self.customer_loc, func=all
)
)
self.assertFalse(
self.shelf1_loc.is_sublocation_of(
self.supplier_loc | self.customer_loc, func=all
)
)
| 33.875
| 1,626
|
721
|
py
|
PYTHON
|
15.0
|
# Copyright 2020-2021 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo.tests import TransactionCase
class StockHelperCommonCase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.wh = cls.env.ref("stock.warehouse0")
cls.customer_loc = cls.env.ref("stock.stock_location_customers")
cls.supplier_loc = cls.env.ref("stock.stock_location_suppliers")
cls.stock_loc = cls.wh.lot_stock_id
cls.shelf1_loc = cls.env.ref("stock.stock_location_components")
cls.shelf2_loc = cls.env.ref("stock.stock_location_14")
| 37.947368
| 721
|
788
|
py
|
PYTHON
|
15.0
|
# Copyright 2020-2021 Camptocamp SA (http://www.camptocamp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import models
class StockLocation(models.Model):
_inherit = "stock.location"
def is_sublocation_of(self, others, func=any):
"""Return True if self is a sublocation of others (or equal)
By default, it return True if any other is a parent or equal.
``all`` can be passed to ``func`` to require all the other locations
to be parent or equal to be True.
"""
self.ensure_one()
# Efficient way to verify that the current location is
# below one of the other location without using SQL.
return func(self.parent_path.startswith(other.parent_path) for other in others)
| 39.4
| 788
|
684
|
py
|
PYTHON
|
15.0
|
# Copyright 2016-20 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Stock Demand Estimate",
"summary": "Allows to create demand estimates.",
"version": "15.0.1.1.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"development_status": "Production/Stable",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse",
"depends": ["stock"],
"data": [
"security/ir.model.access.csv",
"security/stock_security.xml",
"views/stock_demand_estimate_view.xml",
],
"license": "LGPL-3",
"installable": True,
}
| 36
| 684
|
6,558
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-19 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from datetime import date, timedelta as td
from odoo.tests.common import TransactionCase
class TestStockDemandEstimate(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.res_users_model = cls.env["res.users"]
cls.product_model = cls.env["product.product"]
cls.stock_location_model = cls.env["stock.location"]
cls.estimate_model = cls.env["stock.demand.estimate"]
cls.g_stock_manager = cls.env.ref("stock.group_stock_manager")
cls.g_stock_user = cls.env.ref("stock.group_stock_user")
cls.company = cls.env.ref("base.main_company")
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
cls.uom_dozen = cls.env.ref("uom.product_uom_dozen")
# Create users:
cls.manager = cls._create_user("user_1", [cls.g_stock_manager], cls.company).id
cls.user = cls._create_user("user_2", [cls.g_stock_user], cls.company).id
# Create a product:
cls.product_1 = cls.product_model.create(
{
"name": "Test Product 1",
"type": "product",
"default_code": "PROD1",
"uom_id": cls.uom_unit.id,
}
)
# Create a location:
cls.location = cls.stock_location_model.create(
{"name": "Place", "usage": "production"}
)
@classmethod
def _create_user(cls, login, groups, company):
group_ids = [group.id for group in groups]
user = cls.res_users_model.create(
{
"name": login,
"login": login,
"password": "demo",
"email": "example@yourcompany.com",
"company_id": company.id,
"company_ids": [(4, company.id)],
"groups_id": [(6, 0, group_ids)],
}
)
return user
def test_01_create_estimate(self):
"""Crete an estimate entering manually the date from and date to."""
date_from = date.today() + td(days=10)
date_to = date.today() + td(days=19)
estimate = self.estimate_model.create(
{
"product_id": self.product_1.id,
"location_id": self.location.id,
"manual_date_from": date_from,
"manual_date_to": date_to,
"product_uom_qty": 500.0,
}
)
self.assertEqual(estimate.date_from, date_from)
self.assertEqual(estimate.date_to, date_to)
self.assertEqual(estimate.duration, 10)
self.assertEqual(estimate.product_qty, 500.0)
self.assertEqual(estimate.daily_qty, 500.0 / 10.0)
def test_02_create_estimate_by_duration_and_different_uom(self):
"""Create an estimate entering manually the date from, duration and
using a different UoM than product's."""
date_from = date.today() + td(days=10)
estimate = self.estimate_model.create(
{
"product_id": self.product_1.id,
"location_id": self.location.id,
"manual_date_from": date_from,
"manual_duration": 15,
"product_uom_qty": 100.0,
"product_uom": self.uom_dozen.id,
}
)
self.assertEqual(estimate.date_from, date_from)
expected_date_to = estimate.date_from + td(days=15 - 1)
self.assertEqual(estimate.date_to, expected_date_to)
self.assertEqual(estimate.duration, 15)
expected_qty = 100 * 12.0 # 100 dozens -> units
self.assertEqual(estimate.product_qty, expected_qty)
self.assertEqual(estimate.daily_qty, expected_qty / 15)
def test_03_get_qty_by_range(self):
date_from = date.today() + td(days=10)
date_to = date.today() + td(days=19)
estimate = self.estimate_model.create(
{
"product_id": self.product_1.id,
"location_id": self.location.id,
"manual_date_from": date_from,
"manual_date_to": date_to,
"product_uom_qty": 100.0,
}
)
self.assertEqual(estimate.duration, 10.0)
self.assertEqual(estimate.daily_qty, 10.0)
res = estimate.get_quantity_by_date_range(
date_from + td(days=3), date_from + td(days=17)
)
self.assertEqual(res, 70)
res = estimate.get_quantity_by_date_range(
date_from + td(days=3), date_from + td(days=7)
)
self.assertEqual(res, 50)
# get full period
res = estimate.get_quantity_by_date_range(date.today(), date_from + td(days=17))
self.assertEqual(res, 100)
# Get exact period:
res = estimate.get_quantity_by_date_range(estimate.date_from, estimate.date_to)
self.assertEqual(res, 100)
# Ask for interval out fo the estimate's:
res = estimate.get_quantity_by_date_range(
date.today(), date.today() + td(days=8)
)
self.assertEqual(res, 0)
def test_04_name_get(self):
date_from = date.today() + td(days=10)
estimate = self.estimate_model.create(
{
"product_id": self.product_1.id,
"location_id": self.location.id,
"manual_date_from": date_from,
"manual_duration": False, # to test else case in _compute_dates.
"product_uom_qty": 500.0,
}
)
res = estimate.name_get()
self.assertEqual(len(res), 1)
rec_id, name_get = res[0]
self.assertEqual(estimate.id, rec_id)
self.assertIn(self.product_1.name, name_get)
def test_05_onchange_methods(self):
date_from = date.today() + td(days=10)
date_to = date.today() + td(days=19)
estimate = self.estimate_model.new(
{
"product_id": self.product_1.id,
"location_id": self.location.id,
"manual_date_from": date_from,
"manual_date_to": date_to,
"product_uom_qty": 500.0,
}
)
estimate._onchange_manual_date_to()
self.assertEqual(estimate.manual_duration, 10)
# Change duration manually:
estimate.manual_duration = 5
estimate._onchange_manual_duration()
self.assertEqual(estimate.manual_date_to, date_from + td(days=4))
| 39.269461
| 6,558
|
5,033
|
py
|
PYTHON
|
15.0
|
# Copyright 2016-20 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright 2016 Aleph Objects, Inc. (https://www.alephobjects.com/)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from datetime import date, timedelta
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class StockDemandEstimate(models.Model):
_name = "stock.demand.estimate"
_description = "Stock Demand Estimate Line"
date_from = fields.Date(
compute="_compute_dates", string="From (computed)", store=True
)
date_to = fields.Date(compute="_compute_dates", string="To (computed)", store=True)
manual_date_from = fields.Date(string="From")
manual_date_to = fields.Date(string="To")
manual_duration = fields.Integer(
string="Duration", help="Duration (in days)", default=1
)
duration = fields.Integer(
compute="_compute_dates", string="Duration (computed))", store=True
)
product_id = fields.Many2one(
comodel_name="product.product", string="Product", required=True
)
product_uom = fields.Many2one(comodel_name="uom.uom", string="Unit of measure")
location_id = fields.Many2one(
comodel_name="stock.location", string="Location", required=True
)
product_uom_qty = fields.Float(string="Quantity", digits="Product Unit of Measure")
product_qty = fields.Float(
string="Quantity (Product UoM)",
compute="_compute_product_quantity",
inverse="_inverse_product_quantity",
digits=0,
store=True,
help="Quantity in the default UoM of the product",
readonly=True,
)
daily_qty = fields.Float(string="Quantity / Day", compute="_compute_daily_qty")
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
required=True,
default=lambda self: self.env.company,
)
@api.depends("manual_duration", "manual_date_from", "manual_date_to")
def _compute_dates(self):
today = date.today()
for rec in self:
rec.date_from = rec.manual_date_from or today
if rec.manual_date_to:
rec.date_to = rec.manual_date_to
rec.duration = (rec.manual_date_to - rec.date_from).days + 1
elif rec.manual_duration:
rec.date_to = rec.date_from + timedelta(days=rec.manual_duration - 1)
rec.duration = rec.manual_duration
else:
rec.date_to = rec.date_from + timedelta(days=1)
rec.duration = 2
@api.depends("product_qty", "duration")
def _compute_daily_qty(self):
for rec in self:
if rec.duration:
rec.daily_qty = rec.product_qty / rec.duration
else:
rec.daily_qty = 0.0
@api.depends("product_id", "product_uom", "product_uom_qty")
def _compute_product_quantity(self):
for rec in self:
if rec.product_uom:
rec.product_qty = rec.product_uom._compute_quantity(
rec.product_uom_qty, rec.product_id.uom_id
)
else:
rec.product_qty = rec.product_uom_qty
def _inverse_product_quantity(self):
raise UserError(
_(
"The requested operation cannot be "
"processed because of a programming error "
"setting the `product_qty` field instead "
"of the `product_uom_qty`."
)
)
def name_get(self):
res = []
for rec in self:
name = "{} - {}: {} - {}".format(
rec.date_from, rec.date_to, rec.product_id.name, rec.location_id.name
)
res.append((rec.id, name))
return res
@api.onchange("manual_date_to")
def _onchange_manual_date_to(self):
for rec in self:
if rec.manual_date_from:
rec.manual_duration = (
rec.manual_date_to - rec.manual_date_from
).days + 1
@api.onchange("manual_duration")
def _onchange_manual_duration(self):
for rec in self:
if rec.manual_date_from:
rec.manual_date_to = rec.manual_date_from + timedelta(
days=rec.manual_duration - 1
)
@api.model
def get_quantity_by_date_range(self, date_start, date_end):
"""To be used in other modules"""
# Check if the dates overlap with the period
period_date_start = self.date_from
period_date_end = self.date_to
# We need only the periods that overlap
# the dates introduced by the user.
if period_date_start <= date_end and period_date_end >= date_start:
overlap_date_start = max(period_date_start, date_start)
overlap_date_end = min(period_date_end, date_end)
days = (abs(overlap_date_end - overlap_date_start)).days + 1
return days * self.daily_qty
return 0.0
| 37.559701
| 5,033
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
3,045
|
py
|
PYTHON
|
15.0
|
import setuptools
with open('VERSION.txt', 'r') as f:
version = f.read().strip()
setuptools.setup(
name="odoo-addons-oca-stock-logistics-warehouse",
description="Meta package for oca-stock-logistics-warehouse Odoo addons",
version=version,
install_requires=[
'odoo-addon-account_move_line_product>=15.0dev,<15.1dev',
'odoo-addon-account_move_line_stock_info>=15.0dev,<15.1dev',
'odoo-addon-procurement_auto_create_group>=15.0dev,<15.1dev',
'odoo-addon-sale_stock_available_info_popup>=15.0dev,<15.1dev',
'odoo-addon-scrap_reason_code>=15.0dev,<15.1dev',
'odoo-addon-stock_archive_constraint>=15.0dev,<15.1dev',
'odoo-addon-stock_available>=15.0dev,<15.1dev',
'odoo-addon-stock_available_immediately>=15.0dev,<15.1dev',
'odoo-addon-stock_available_mrp>=15.0dev,<15.1dev',
'odoo-addon-stock_available_unreserved>=15.0dev,<15.1dev',
'odoo-addon-stock_change_qty_reason>=15.0dev,<15.1dev',
'odoo-addon-stock_demand_estimate>=15.0dev,<15.1dev',
'odoo-addon-stock_demand_estimate_matrix>=15.0dev,<15.1dev',
'odoo-addon-stock_free_quantity>=15.0dev,<15.1dev',
'odoo-addon-stock_helper>=15.0dev,<15.1dev',
'odoo-addon-stock_inventory>=15.0dev,<15.1dev',
'odoo-addon-stock_inventory_discrepancy>=15.0dev,<15.1dev',
'odoo-addon-stock_location_lockdown>=15.0dev,<15.1dev',
'odoo-addon-stock_location_route_description>=15.0dev,<15.1dev',
'odoo-addon-stock_lot_filter_available>=15.0dev,<15.1dev',
'odoo-addon-stock_move_location>=15.0dev,<15.1dev',
'odoo-addon-stock_mts_mto_rule>=15.0dev,<15.1dev',
'odoo-addon-stock_orderpoint_generator>=15.0dev,<15.1dev',
'odoo-addon-stock_orderpoint_move_link>=15.0dev,<15.1dev',
'odoo-addon-stock_orderpoint_purchase_link>=15.0dev,<15.1dev',
'odoo-addon-stock_orderpoint_uom>=15.0dev,<15.1dev',
'odoo-addon-stock_packaging_calculator>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_orig_dest_link>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_show_linked>=15.0dev,<15.1dev',
'odoo-addon-stock_putaway_product_template>=15.0dev,<15.1dev',
'odoo-addon-stock_quant_cost_info>=15.0dev,<15.1dev',
'odoo-addon-stock_quant_manual_assign>=15.0dev,<15.1dev',
'odoo-addon-stock_request>=15.0dev,<15.1dev',
'odoo-addon-stock_request_analytic>=15.0dev,<15.1dev',
'odoo-addon-stock_request_kanban>=15.0dev,<15.1dev',
'odoo-addon-stock_request_mrp>=15.0dev,<15.1dev',
'odoo-addon-stock_request_purchase>=15.0dev,<15.1dev',
'odoo-addon-stock_request_separate_picking>=15.0dev,<15.1dev',
'odoo-addon-stock_reserve>=15.0dev,<15.1dev',
'odoo-addon-stock_secondary_unit>=15.0dev,<15.1dev',
'odoo-addon-stock_warehouse_calendar>=15.0dev,<15.1dev',
],
classifiers=[
'Programming Language :: Python',
'Framework :: Odoo',
'Framework :: Odoo :: 15.0',
]
)
| 52.5
| 3,045
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
511
|
py
|
PYTHON
|
15.0
|
# Copyright 2014 Numérigraphe SARL, Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Consider the production potential is available to promise",
"version": "15.0.1.0.1",
"author": "Numérigraphe," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Hidden",
"depends": ["stock_available", "mrp"],
"demo": ["demo/mrp_data.xml"],
"license": "AGPL-3",
"installable": True,
}
| 39.153846
| 509
|
15,937
|
py
|
PYTHON
|
15.0
|
# Copyright 2014 Numérigraphe SARL
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.osv.expression import TRUE_LEAF
from odoo.tests.common import TransactionCase
class TestPotentialQty(TransactionCase):
"""Test the potential quantity on a product with a multi-line BoM"""
@classmethod
def setUpClass(cls):
super(TestPotentialQty, cls).setUpClass()
cls.product_model = cls.env["product.product"]
cls.bom_model = cls.env["mrp.bom"]
cls.bom_line_model = cls.env["mrp.bom.line"]
cls.stock_quant_model = cls.env["stock.quant"]
cls.config = cls.env["ir.config_parameter"]
cls.location = cls.env["stock.location"]
cls.main_company = cls.env.ref("base.main_company")
# Get the warehouses
cls.wh_main = cls.env.ref("stock.warehouse0")
cls.wh_ch = cls.env.ref("stock.stock_warehouse_shop0")
# We need to compute parent_left and parent_right of the locations as
# they are used to compute qty_available of the product.
cls.location._parent_store_compute()
cls.setup_demo_data()
@classmethod
def setup_demo_data(cls):
# An interesting product (multi-line BoM, variants)
cls.tmpl = cls.env.ref("mrp.product_product_table_kit_product_template")
# First variant
cls.var1 = cls.env.ref("mrp.product_product_table_kit")
cls.var1.type = "product"
# Second variant
cls.var2 = cls.env.ref("stock_available_mrp.product_kit_1a")
cls.var2.type = "product"
# Make bolt a stockable product to be able to change its stock
# we need to unreserve the existing move before being able to do it.
bolt = cls.env.ref("mrp.product_product_computer_desk_bolt")
bolt.stock_move_ids._do_unreserve()
bolt.type = "product"
# Components that can be used to make the product
components = [
# Bolt
bolt,
# Wood Panel
cls.env.ref("mrp.product_product_wood_panel"),
]
# Zero-out the inventory of all variants and components
for component in components + [v for v in cls.tmpl.product_variant_ids]:
moves = component.stock_move_ids.filtered(
lambda mo: mo.state not in ("done", "cancel")
)
moves._action_cancel()
component.stock_quant_ids.unlink()
# A product without a BoM
cls.product_wo_bom = cls.env.ref("product.product_product_11")
# Record the initial quantity available for sale
cls.initial_usable_qties = {
i.id: i.immediately_usable_qty
for i in [cls.tmpl, cls.var1, cls.var2, cls.product_wo_bom]
}
def create_inventory(self, product, qty, location=None, company_id=None):
if location is None:
location = self.wh_main.lot_stock_id
if company_id:
self.env["stock.quant"].with_company(company_id)._update_available_quantity(
product, location, qty
)
else:
self.env["stock.quant"]._update_available_quantity(product, location, qty)
def create_simple_bom(self, product, sub_product, product_qty=1, sub_product_qty=1):
bom = self.bom_model.create(
{
"product_tmpl_id": product.product_tmpl_id.id,
"product_id": product.id,
"product_qty": product_qty,
}
)
self.bom_line_model.create(
{
"bom_id": bom.id,
"product_id": sub_product.id,
"product_qty": sub_product_qty,
}
)
return bom
def assertPotentialQty(self, record, qty, msg):
record.refresh()
# Check the potential
self.assertEqual(record.potential_qty, qty, msg)
# Check the variation of quantity available for sale
self.assertEqual(
(record.immediately_usable_qty - self.initial_usable_qties[record.id]),
qty,
msg,
)
def test_01_potential_qty_no_bom(self):
# Check the potential when there's no BoM
self.assertPotentialQty(
self.product_wo_bom, 0.0, "The potential without a BoM should be 0"
)
def test_02_potential_qty_no_bom_for_company(self):
chicago_id = self.ref("stock.res_company_1")
# Receive 1000x Wood Panel owned by Chicago
self.create_inventory(
product=self.env.ref("mrp.product_product_wood_panel"),
qty=1000.0,
location=self.wh_ch.lot_stock_id,
company_id=chicago_id,
)
# Put Bolt owned by Chicago for 1000x the 1st variant in main WH
self.create_inventory(
product=self.env.ref("mrp.product_product_computer_desk_bolt"),
qty=1000.0,
location=self.wh_ch.lot_stock_id,
company_id=chicago_id,
)
self.assertPotentialQty(
self.tmpl, 250.0, "Wrong template potential after receiving components"
)
test_user = self.env["res.users"].create(
{
"name": "test_demo",
"login": "test_demo",
"company_id": self.main_company.id,
"company_ids": [(4, self.main_company.id), (4, chicago_id)],
"groups_id": [
(4, self.ref("stock.group_stock_user")),
(4, self.ref("mrp.group_mrp_user")),
],
}
)
bom = self.env["mrp.bom"].search([("product_tmpl_id", "=", self.tmpl.id)])
test_user_tmpl = self.tmpl.with_user(test_user)
self.assertPotentialQty(
test_user_tmpl, 250.0, "Simple user can access to the potential_qty"
)
# Set the bom on the main company (visible to members of main company)
# and all products without company (visible to all)
# and the demo user on Chicago (child of main company)
self.env["product.product"].search([TRUE_LEAF]).write({"company_id": False})
test_user.write({"company_ids": [(6, 0, self.main_company.ids)]})
bom.company_id = self.main_company
self.assertPotentialQty(
test_user_tmpl,
0,
"The bom should not be visible to non members of the bom's "
"company or company child of the bom's company",
)
bom.company_id = chicago_id
test_user.write({"company_ids": [(4, chicago_id)]})
self.assertPotentialQty(test_user_tmpl, 250.0, "")
def test_03_potential_qty(self):
for i in [self.tmpl, self.var1, self.var2]:
self.assertPotentialQty(i, 0.0, "The potential quantity should start at 0")
# Receive 1000x Wood Panel
self.create_inventory(
product=self.env.ref("mrp.product_product_wood_panel"),
qty=1000.0,
location=self.wh_main.lot_stock_id,
)
for i in [self.tmpl, self.var1, self.var2]:
self.assertPotentialQty(
i,
0.0,
"Receiving a single component should not change the "
"potential of %s" % i,
)
# Receive enough bolt to make 1000x the 1st variant in main WH
self.create_inventory(
product=self.env.ref("mrp.product_product_computer_desk_bolt"),
qty=1000.0,
location=self.wh_main.lot_stock_id,
)
self.assertPotentialQty(
self.tmpl, 250.0, "Wrong template potential after receiving components"
)
self.assertPotentialQty(
self.var1, 250.0, "Wrong variant 1 potential after receiving components"
)
self.assertPotentialQty(
self.var2,
0.0,
"Receiving variant 1's component should not change "
"variant 2's potential",
)
# Receive enough components to make 213 the 2nd variant at Chicago
self.create_inventory(
self.env.ref("mrp.product_product_wood_panel"),
1000.0,
self.wh_ch.lot_stock_id,
self.ref("stock.res_company_1"),
)
self.create_inventory(
self.env.ref("stock_available_mrp.product_computer_desk_bolt_white"),
852.0,
self.wh_ch.lot_stock_id,
self.ref("stock.res_company_1"),
)
self.assertPotentialQty(
self.tmpl.with_context(test=True),
250.0,
"Wrong template potential after receiving components",
)
self.assertPotentialQty(
self.var1,
250.0,
"Receiving variant 2's component should not change "
"variant 1's potential",
)
self.assertPotentialQty(
self.var2, 213.0, "Wrong variant 2 potential after receiving components"
)
# Check by warehouse
self.assertPotentialQty(
self.tmpl.with_context(warehouse=self.wh_main.id),
250.0,
"Wrong potential quantity in main WH",
)
self.assertPotentialQty(
self.tmpl.with_context(warehouse=self.wh_ch.id),
213.0,
"Wrong potential quantity in Chicago WH",
)
# Check by location
self.assertPotentialQty(
self.tmpl.with_context(location=self.wh_main.lot_stock_id.id),
250.0,
"Wrong potential quantity in main WH location",
)
self.assertPotentialQty(
self.tmpl.with_context(location=self.wh_ch.lot_stock_id.id),
213.0,
"Wrong potential quantity in Chicago WH location",
)
def test_04_multi_unit_recursive_bom(self):
# Test multi-level and multi-units BOM
uom_unit = self.env.ref("uom.product_uom_unit")
uom_unit.rounding = 1.0
p1 = self.product_model.create(
{
"name": "Test product with BOM",
"type": "product",
"uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
p2 = self.product_model.create(
{
"name": "Test sub product with BOM",
"type": "consu",
"uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
p3 = self.product_model.create(
{
"name": "Test component",
"type": "product",
"uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
bom_p1 = self.bom_model.create(
{"product_tmpl_id": p1.product_tmpl_id.id, "product_id": p1.id}
)
self.bom_line_model.create(
{
"bom_id": bom_p1.id,
"product_id": p3.id,
"product_qty": 1,
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
# Two p2 which have a bom
self.bom_line_model.create(
{
"bom_id": bom_p1.id,
"product_id": p2.id,
"product_qty": 2,
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
bom_p2 = self.bom_model.create(
{
"product_tmpl_id": p2.product_tmpl_id.id,
"product_id": p2.id,
"type": "phantom",
}
)
# p2 need 2 unit of component
self.bom_line_model.create(
{
"bom_id": bom_p2.id,
"product_id": p3.id,
"product_qty": 2,
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
p1.refresh()
# Need a least 5 units for one P1
self.assertEqual(0, p1.potential_qty)
self.create_inventory(p3, 1)
p1.refresh()
self.assertEqual(0, p1.potential_qty)
self.create_inventory(p3, 3)
p1.refresh()
self.assertEqual(0, p1.potential_qty)
self.create_inventory(p3, 5)
p1.refresh()
self.assertEqual(1.0, p1.potential_qty)
self.create_inventory(p3, 6)
p1.refresh()
self.assertEqual(3.0, p1.potential_qty)
self.create_inventory(p3, 10)
p1.refresh()
self.assertEqual(5.0, p1.potential_qty)
def test_05_potential_qty_list(self):
# Try to highlight a bug when _get_potential_qty is called on
# a recordset with multiple products
# Recursive compute is not working
p1 = self.product_model.create({"name": "Test P1"})
p2 = self.product_model.create({"name": "Test P2"})
p3 = self.product_model.create({"name": "Test P3", "type": "product"})
self.config.set_param("stock_available_mrp_based_on", "immediately_usable_qty")
# P1 need one P2
self.create_simple_bom(p1, p2)
# P2 need one P3
self.create_simple_bom(p2, p3)
self.create_inventory(p3, 3)
self.product_model.invalidate_cache()
products = self.product_model.search([("id", "in", [p1.id, p2.id, p3.id])])
self.assertEqual(
{p1.id: 3.0, p2.id: 3.0, p3.id: 0.0},
{p.id: p.potential_qty for p in products},
)
def test_product_phantom(self):
# Create a BOM product with 2 components
# Set stock quantity for the first one == 0.0
# Set stock quantity for the second one == 1.0
# Create an incoming movement for the first component
# The immediately available quantity should stay == 0.0
uom_unit = self.env.ref("uom.product_uom_unit")
uom_unit.rounding = 1.0
product = self.product_model.create(
{
"name": "Test product with BOM",
"type": "product",
"uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
bom = self.bom_model.create(
{
"product_tmpl_id": product.product_tmpl_id.id,
"product_id": product.id,
"type": "phantom",
}
)
bom_product = self.product_model.create(
{
"name": "BOM product",
"type": "product",
"uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
self.bom_line_model.create(
{
"bom_id": bom.id,
"product_id": bom_product.id,
"product_qty": 1,
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
bom_product_2 = self.product_model.create(
{
"name": "BOM product 2",
"type": "product",
"uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
self.bom_line_model.create(
{
"bom_id": bom.id,
"product_id": bom_product_2.id,
"product_qty": 1,
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
self.create_inventory(bom_product_2, 1)
move_in = self.env["stock.move"].create(
{
"name": bom_product.name,
"location_id": self.env.ref("stock.stock_location_suppliers").id,
"location_dest_id": self.env.ref("stock.stock_location_stock").id,
"product_id": bom_product.id,
"product_uom_qty": 1.0,
"product_uom": self.env.ref("uom.product_uom_unit").id,
}
)
move_in._action_confirm()
product.invalidate_cache()
self.assertEqual(product.immediately_usable_qty, 0.0)
| 35.165563
| 15,930
|
6,682
|
py
|
PYTHON
|
15.0
|
# Copyright 2014 Numérigraphe SARL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from collections import Counter
from odoo import api, models
from odoo.fields import first
from odoo.tools import float_round
class ProductProduct(models.Model):
_inherit = "product.product"
@api.depends("virtual_available", "bom_ids", "bom_ids.product_qty")
def _compute_available_quantities(self):
res = super()._compute_available_quantities()
return res
def _compute_available_quantities_dict(self):
res, stock_dict = super()._compute_available_quantities_dict()
# compute qty for product with bom
product_with_bom = self.filtered("bom_ids")
if not product_with_bom:
return res, stock_dict
icp = self.env["ir.config_parameter"]
stock_available_mrp_based_on = icp.sudo().get_param(
"stock_available_mrp_based_on", "qty_available"
)
# explode all boms at once
exploded_boms = product_with_bom._explode_boms()
# extract the list of product used as bom component
component_products = self.env["product.product"].browse()
for exploded_components in exploded_boms.values():
for bom_component in exploded_components:
component_products |= first(bom_component).product_id
# Compute stock for product components.
# {'productid': {field_name: qty}}
if res and stock_available_mrp_based_on in list(res.values())[0]:
# If the qty is computed by the same method use it to avoid
# stressing the cache
component_qties, _ = component_products._compute_available_quantities_dict()
else:
# The qty is a field computed by an other method than the
# current one. Take the value on the record.
component_qties = {
p.id: {stock_available_mrp_based_on: p[stock_available_mrp_based_on]}
for p in component_products
}
for product in product_with_bom:
# Need by product (same product can be in many BOM lines/levels)
bom_id = first(product.bom_ids)
exploded_components = exploded_boms[product.id]
component_needs = product._get_components_needs(exploded_components)
if not component_needs:
# The BoM has no line we can use
potential_qty = 0.0
else:
# Find the lowest quantity we can make with the stock at hand
components_potential_qty = min(
component_qties[component.id][stock_available_mrp_based_on] / need
for component, need in component_needs.items()
)
potential_qty = bom_id.product_qty * components_potential_qty
potential_qty = potential_qty > 0.0 and potential_qty or 0.0
# We want to respect the rounding factor of the potential_qty
# Rounding down as we want to be pesimistic.
potential_qty = bom_id.product_uom_id._compute_quantity(
potential_qty,
bom_id.product_tmpl_id.uom_id,
rounding_method="DOWN",
)
res[product.id]["potential_qty"] = potential_qty
res[product.id]["immediately_usable_qty"] = potential_qty
return res, stock_dict
def _explode_boms(self):
"""
return a dict by product_id of exploded bom lines
:return:
"""
return self.explode_bom_quantities()
@api.model
def _get_components_needs(self, exploded_components):
"""Return the needed qty of each compoments in the exploded_components
:type exploded_components
:rtype: collections.Counter
"""
needs = Counter()
for bom_line, bom_qty in exploded_components:
component = bom_line.product_id
needs += Counter({component: bom_qty})
return needs
def explode_bom_quantities(self):
"""Explode a bill of material with quantities to consume
It returns a dict with the exploded bom lines and
the quantity they consume. Example::
{
<product-id>: [
(<bom-line-id>, <quantity>)
(<bom-line-id>, <quantity>)
]
}
The 'MrpBom.explode()' method includes the same information, with other
things, but is under-optimized to be used for the purpose of this
module. The killer is particularly the call to `_bom_find()` which can
generate thousands of SELECT for searches.
"""
result = {}
for product in self:
lines_done = []
bom_lines = [
(first(product.bom_ids), bom_line, product, 1.0)
for bom_line in first(product.bom_ids).bom_line_ids
]
while bom_lines:
(current_bom, current_line, current_product, current_qty) = bom_lines[0]
bom_lines = bom_lines[1:]
if current_line._skip_bom_line(current_product):
continue
line_quantity = current_qty * current_line.product_qty
sub_bom = first(current_line.product_id.bom_ids)
if sub_bom.type == "phantom":
product_uom = current_line.product_uom_id
converted_line_quantity = product_uom._compute_quantity(
line_quantity / sub_bom.product_qty,
sub_bom.product_uom_id,
)
bom_lines = [
(
sub_bom,
line,
current_line.product_id,
converted_line_quantity,
)
for line in sub_bom.bom_line_ids
] + bom_lines
else:
# We round up here because the user expects that if he has
# to consume a little more, the whole UOM unit should be
# consumed.
rounding = current_line.product_uom_id.rounding
line_quantity = float_round(
line_quantity,
precision_rounding=rounding,
rounding_method="UP",
)
lines_done.append((current_line, line_quantity))
result[product.id] = lines_done
return result
| 39.070175
| 6,681
|
650
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Stock Warehouse Calendar",
"summary": "Adds a calendar to the Warehouse",
"version": "15.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"author": "ForgeFlow, " "Odoo Community Association (OCA)",
"category": "Warehouse Management",
"depends": ["stock", "resource"],
"data": ["views/stock_warehouse_views.xml"],
"installable": True,
"development_status": "Production/Stable",
"maintainers": ["JordiBForgeFlow"],
}
| 38.235294
| 650
|
4,580
|
py
|
PYTHON
|
15.0
|
# Copyright 2018-19 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import fields
from odoo.tests.common import TransactionCase
class TestStockWarehouseCalendar(TransactionCase):
def setUp(self):
super(TestStockWarehouseCalendar, self).setUp()
self.wh_obj = self.env["stock.warehouse"]
self.move_obj = self.env["stock.move"]
self.pg_obj = self.env["procurement.group"]
self.company = self.env.ref("base.main_company")
self.warehouse = self.env.ref("stock.warehouse0")
self.customer_loc = self.env.ref("stock.stock_location_customers")
self.company_partner = self.env.ref("base.main_partner")
self.calendar = self.env.ref("resource.resource_calendar_std")
self.warehouse.calendar_id = self.calendar
self.warehouse_2 = self.wh_obj.create(
{"code": "WH-T", "name": "Warehouse Test", "calendar_id": self.calendar.id}
)
self.warehouse_3 = self.wh_obj.create(
{"code": "WH-no-calendar", "name": "Warehouse Test 2"}
)
self.product = self.env["product.product"].create(
{"name": "test product", "default_code": "PRD", "type": "product"}
)
route_vals = {"name": "WH2 -> WH"}
self.transfer_route = self.env["stock.location.route"].create(route_vals)
rule_vals = {
"location_id": self.warehouse.lot_stock_id.id,
"location_src_id": self.warehouse_2.lot_stock_id.id,
"action": "pull_push",
"warehouse_id": self.warehouse.id,
"propagate_warehouse_id": self.warehouse_2.id,
"picking_type_id": self.env.ref("stock.picking_type_internal").id,
"name": "WH2->WH",
"route_id": self.transfer_route.id,
"delay": 1,
}
self.transfer_rule = self.env["stock.rule"].create(rule_vals)
self.product.route_ids = [(6, 0, self.transfer_route.ids)]
def test_01_procurement_with_calendar(self):
values = {
"date_planned": "2097-01-07 09:00:00", # Monday
"warehouse_id": self.warehouse,
"company_id": self.company,
"rule_id": self.transfer_rule,
}
self.pg_obj.run(
[
self.pg_obj.Procurement(
self.product,
100,
self.product.uom_id,
self.warehouse.lot_stock_id,
"Test",
"Test",
self.warehouse.company_id,
values,
)
]
)
move = self.env["stock.move"].search(
[("product_id", "=", self.product.id)], limit=1
)
date = fields.Date.to_date(move.date)
# Friday 4th Jan 2017
friday = fields.Date.to_date("2097-01-04 09:00:00")
self.assertEqual(date, friday)
def test_02_procurement_with_calendar_early(self):
"""Test procuring at the beginning of the day, with no work intervals
before."""
values = {
"date_planned": "2097-01-07 01:00:00", # Monday
"warehouse_id": self.warehouse,
"company_id": self.company,
"rule_id": self.transfer_rule,
}
self.pg_obj.run(
[
self.pg_obj.Procurement(
self.product,
100,
self.product.uom_id,
self.warehouse.lot_stock_id,
"Test",
"Test",
self.warehouse.company_id,
values,
)
]
)
move = self.env["stock.move"].search(
[("product_id", "=", self.product.id)], limit=1
)
date = fields.Date.to_date(move.date)
# Friday 4th Jan 2017
friday = fields.Date.to_date("2097-01-04 09:00:00")
self.assertEqual(date, friday)
def test_03_wh_plan_days_future(self):
"""Test plan days helper in warehouse."""
reference = "2097-01-09 12:00:00" # Wednesday
# With calendar
result = self.warehouse_2.wh_plan_days(reference, 3).date()
next_monday = fields.Date.to_date("2097-01-14")
self.assertEqual(result, next_monday)
# Without calendar
result = self.warehouse_3.wh_plan_days(reference, 3).date()
saturday = fields.Date.to_date("2097-01-12")
self.assertEqual(result, saturday)
| 38.166667
| 4,580
|
1,524
|
py
|
PYTHON
|
15.0
|
# Copyright 2018-19 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from datetime import datetime, timedelta
from odoo import fields, models
class StockWarehouse(models.Model):
_inherit = "stock.warehouse"
calendar_id = fields.Many2one(
comodel_name="resource.calendar", string="Working Hours"
)
def wh_plan_days(self, date_from, delta):
"""Helper method to schedule warehouse operations based on its
working days (if set).
:param datetime date_from: reference date.
:param integer delta: offset to apply.
:return: datetime: resulting date.
"""
self.ensure_one()
if isinstance(delta, float):
delta = round(delta)
if not isinstance(date_from, datetime):
date_from = fields.Datetime.to_datetime(date_from)
if delta == 0:
return date_from
if self.calendar_id:
if delta < 0:
# We force the date planned to be at the beginning of the day.
# So no work intervals are found in the reference date.
dt_planned = date_from.replace(hour=0)
else:
# We force the date planned at the end of the day.
dt_planned = date_from.replace(hour=23)
date_result = self.calendar_id.plan_days(delta, dt_planned)
else:
date_result = date_from + timedelta(days=delta)
return date_result
| 35.44186
| 1,524
|
926
|
py
|
PYTHON
|
15.0
|
# Copyright 2018-19 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import models
class StockRule(models.Model):
_inherit = "stock.rule"
def _get_stock_move_values(
self,
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
):
res = super(StockRule, self)._get_stock_move_values(
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
)
warehouse = self.propagate_warehouse_id or self.warehouse_id
if warehouse.calendar_id and self.delay:
date = warehouse.wh_plan_days(values["date_planned"], -1 * self.delay)
res["date"] = date
return res
| 25.722222
| 926
|
1,738
|
py
|
PYTHON
|
15.0
|
# Copyright 2023 ForgeFlow, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from collections import deque
from odoo import SUPERUSER_ID, api
from odoo.tools import sql
_logger = logging.getLogger(__name__)
def pre_init_hook(cr):
_logger.info(
"Create temporary table to avoid the automatic launch of the compute method"
)
if not sql.table_exists(cr, "stock_picking_orig_dest_rel"):
cr.execute(
"""CREATE TABLE stock_picking_orig_dest_rel
(dest_picking_id integer,orig_picking_id integer)"""
)
def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
_logger.info("Dropping temporary table")
cr.execute("DROP TABLE stock_picking_orig_dest_rel")
_logger.info("Creating new table via ORM")
StockPicking = env["stock.picking"]
registry._post_init_queue = deque()
StockPicking._fields["orig_picking_ids"].update_db(StockPicking, False)
StockPicking._fields["dest_picking_ids"].update_db(StockPicking, False)
_logger.info("Filling Origin and Destination Picking relation table")
query = """
WITH query AS (
SELECT spo.id AS orig_picking_id, spd.id AS dest_picking_id
FROM stock_move_move_rel smml
JOIN stock_move smo ON smo.id = smml.move_orig_id
JOIN stock_move smd ON smd.id = smml.move_dest_id
JOIN stock_picking spo ON smo.picking_id = spo.id
JOIN stock_picking spd ON smd.picking_id = spd.id
GROUP BY spo.id, spd.id
)
INSERT INTO stock_picking_orig_dest_rel (orig_picking_id, dest_picking_id)
SELECT * FROM query;
"""
cr.execute(query)
| 37.782609
| 1,738
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.