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 |
|---|---|---|---|---|---|---|
557 | py | PYTHON | 15.0 | # Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Stock landed costs delivery",
"version": "15.0.1.0.0",
"category": "Inventory",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["delivery_purchase", "stock_landed_costs_purchase_auto"],
"data": ["views/delivery_carrier_view.xml"],
"installable": True,
"maintainers": ["victoralmau"],
}
| 39.642857 | 555 |
1,240 | py | PYTHON | 15.0 | # Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo.addons.stock_landed_costs_purchase_auto.tests import test_purchase_order
class TestPurchaseOrder(test_purchase_order.TestPurchaseOrder):
def setUp(self):
super().setUp()
product_carrier = self.env["product.product"].create(
{"name": "Carrier", "detailed_type": "service"}
)
self.carrier = self.env["delivery.carrier"].create(
{
"name": "Test carrier",
"product_id": product_carrier.id,
"fixed_price": 10,
}
)
def test_order_with_lc_carrier_id(self):
order = self._create_purchase_order()
order.carrier_id = self.carrier
order.button_confirm()
lc = order.landed_cost_ids[0]
self.assertTrue(self.carrier.product_id in lc.cost_lines.mapped("product_id"))
lc_cost_line = lc.cost_lines.filtered(
lambda x: x.product_id == self.carrier.product_id
)
self.assertEqual(lc_cost_line.price_unit, 10)
self.assertEqual(
lc_cost_line.split_method, self.carrier.split_method_landed_cost_line
)
| 37.515152 | 1,238 |
863 | py | PYTHON | 15.0 | # Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
def _prepare_landed_cost_line_delivery_values(self):
return {
"product_id": self.carrier_id.product_id.id,
"name": self.carrier_id.name,
"price_unit": self.delivery_price,
"split_method": self.carrier_id.split_method_landed_cost_line,
}
def _prepare_landed_cost_values(self, picking):
res = super()._prepare_landed_cost_values(picking)
if self.carrier_id.create_landed_cost_line:
res.setdefault("cost_lines", [])
res["cost_lines"].append(
(0, 0, self._prepare_landed_cost_line_delivery_values())
)
return res
| 35.875 | 861 |
796 | py | PYTHON | 15.0 | # Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class DeliveryCarrier(models.Model):
_inherit = "delivery.carrier"
@api.model
def _get_selection_split_method_landed_cost_line(self):
model = self.env["stock.landed.cost.lines"]
return model.fields_get(allfields=["split_method"])["split_method"]["selection"]
create_landed_cost_line = fields.Boolean(
string="Allow create landed cost lines", default=True
)
split_method_landed_cost_line = fields.Selection(
selection="_get_selection_split_method_landed_cost_line",
string="Split method",
default="by_quantity",
help="Split method used in landed cost lines",
)
| 36.090909 | 794 |
648 | py | PYTHON | 15.0 | # Copyright 2014 Camptocamp SA - Guewen Baconnier
# Copyright 2018 Tecnativa - Vicent Cubells
# Copyright 2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Picking Mass Action",
"version": "15.0.1.0.1",
"author": "Camptocamp, GRAP, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"license": "AGPL-3",
"category": "Warehouse Management",
"depends": ["stock_account"],
"data": [
"security/ir.model.access.csv",
"wizard/mass_action_view.xml",
"data/ir_cron.xml",
],
}
| 36 | 648 |
4,426 | py | PYTHON | 15.0 | # Copyright 2018 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests import common
class TestMassAction(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
partner = cls.env["res.partner"].create({"name": "Test Partner"})
product = cls.env["product.product"].create(
{"name": "Product Test", "type": "product"}
)
picking_type_out = cls.env.ref("stock.picking_type_out")
stock_location = cls.env.ref("stock.stock_location_stock")
customer_location = cls.env.ref("stock.stock_location_customers")
cls.env["stock.quant"].create(
{
"product_id": product.id,
"location_id": stock_location.id,
"quantity": 600.0,
}
)
# Force Odoo not to automatically reserve the products on the pickings
# so we can test stock.picking.mass.action
picking_type_out.reservation_method = "manual"
# We create a picking out
cls.picking = cls.env["stock.picking"].create(
{
"partner_id": partner.id,
"picking_type_id": picking_type_out.id,
"location_id": stock_location.id,
"location_dest_id": customer_location.id,
"move_lines": [
(
0,
0,
{
"name": product.name,
"product_id": product.id,
"product_uom_qty": 200,
"product_uom": product.uom_id.id,
"location_id": stock_location.id,
"location_dest_id": customer_location.id,
},
)
],
}
)
def test_mass_action(self):
self.assertEqual(self.picking.state, "draft")
wiz = self.env["stock.picking.mass.action"]
# We test confirming a picking
wiz_confirm = wiz.create({"picking_ids": [(4, self.picking.id)]})
wiz_confirm.confirm = True
wiz_confirm.mass_action()
self.assertEqual(self.picking.state, "confirmed")
# We test checking availability
wiz_check = wiz.with_context(check_availability=True).create(
{"picking_ids": [(4, self.picking.id)]}
)
wiz_check.confirm = True
wiz_check.mass_action()
self.assertEqual(self.picking.state, "assigned")
# We test transferring picking
wiz_tranfer = wiz.with_context(transfer=True).create(
{"picking_ids": [(4, self.picking.id)]}
)
wiz_tranfer.confirm = True
for line in self.picking.move_lines:
line.quantity_done = line.product_uom_qty
wiz_tranfer.mass_action()
self.assertEqual(self.picking.state, "done")
# We test checking assign all
pickings = self.env["stock.picking"]
pick1 = self.picking.copy()
pickings |= pick1
pick2 = self.picking.copy()
pickings |= pick2
self.assertEqual(pick1.state, "draft")
self.assertEqual(pick2.state, "draft")
wiz_confirm = wiz.create({"picking_ids": [(6, 0, [pick1.id, pick2.id])]})
wiz_confirm.confirm = True
wiz_confirm.mass_action()
self.assertEqual(pick1.state, "confirmed")
self.assertEqual(pick2.state, "confirmed")
pickings.check_assign_all()
self.assertEqual(pick1.state, "assigned")
self.assertEqual(pick2.state, "assigned")
def test_mass_action_inmediate_transfer(self):
wiz_tranfer = self.env["stock.picking.mass.action"].create(
{"picking_ids": [(4, self.picking.id)], "confirm": True, "transfer": True}
)
res = wiz_tranfer.mass_action()
self.assertEqual(res["res_model"], "stock.immediate.transfer")
def test_mass_action_backorder(self):
wiz_tranfer = self.env["stock.picking.mass.action"].create(
{"picking_ids": [(4, self.picking.id)], "confirm": True, "transfer": True}
)
self.picking.action_assign()
self.picking.move_lines[0].quantity_done = 30
res = wiz_tranfer.mass_action()
self.assertEqual(res["res_model"], "stock.backorder.confirmation")
| 40.981481 | 4,426 |
3,155 | py | PYTHON | 15.0 | # Copyright 2014 Camptocamp SA - Guewen Baconnier
# Copyright 2018 Tecnativa - Vicent Cubells
# Copyright 2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields
from odoo.models import TransientModel
class StockPickingMassAction(TransientModel):
_name = "stock.picking.mass.action"
_description = "Stock Picking Mass Action"
@api.model
def _default_check_availability(self):
return self.env.context.get("check_availability", False)
@api.model
def _default_transfer(self):
return self.env.context.get("transfer", False)
def _default_picking_ids(self):
return self.env["stock.picking"].browse(self.env.context.get("active_ids"))
confirm = fields.Boolean(
string="Mark as Todo",
default=True,
help="check this box if you want to mark as Todo the" " selected Pickings.",
)
check_availability = fields.Boolean(
default=lambda self: self._default_check_availability(),
help="check this box if you want to check the availability of"
" the selected Pickings.",
)
transfer = fields.Boolean(
default=lambda self: self._default_transfer(),
help="check this box if you want to transfer all the selected"
" pickings.\n You'll not have the possibility to realize a"
" partial transfer.\n If you want to do that, please do it"
" manually on the picking form.",
)
picking_ids = fields.Many2many(
string="Pickings",
comodel_name="stock.picking",
default=lambda self: self._default_picking_ids(),
help="",
)
def mass_action(self):
self.ensure_one()
# Get draft pickings and confirm them if asked
if self.confirm:
draft_picking_lst = self.picking_ids.filtered(
lambda x: x.state == "draft"
).sorted(key=lambda r: r.scheduled_date)
draft_picking_lst.action_confirm()
# check availability if asked
if self.check_availability:
pickings_to_check = self.picking_ids.filtered(
lambda x: x.state not in ["draft", "cancel", "done"]
).sorted(key=lambda r: r.scheduled_date)
pickings_to_check.action_assign()
# Get all pickings ready to transfer and transfer them if asked
if self.transfer:
assigned_picking_lst = self.picking_ids.filtered(
lambda x: x.state == "assigned"
).sorted(key=lambda r: r.scheduled_date)
quantities_done = sum(
move_line.qty_done
for move_line in assigned_picking_lst.mapped("move_line_ids").filtered(
lambda m: m.state not in ("done", "cancel")
)
)
if not quantities_done:
return assigned_picking_lst.action_immediate_transfer_wizard()
if any([pick._check_backorder() for pick in assigned_picking_lst]):
return assigned_picking_lst._action_generate_backorder_wizard()
assigned_picking_lst.button_validate()
| 38.950617 | 3,155 |
1,343 | py | PYTHON | 15.0 | # Copyright 2014 Camptocamp SA - Guewen Baconnier
# Copyright 2018 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api
from odoo.models import Model
class StockPicking(Model):
_inherit = "stock.picking"
@api.model
def check_assign_all(self):
"""Try to assign confirmed pickings"""
domain = [("picking_type_code", "=", "outgoing"), ("state", "=", "confirmed")]
records = self.search(domain, order="scheduled_date")
records.action_assign()
def action_immediate_transfer_wizard(self):
view = self.env.ref("stock.view_immediate_transfer")
wiz = self.env["stock.immediate.transfer"].create(
{
"pick_ids": [(4, p.id) for p in self],
"immediate_transfer_line_ids": [
(0, 0, {"to_immediate": True, "picking_id": p.id}) for p in self
],
}
)
return {
"name": _("Immediate Transfer?"),
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": "stock.immediate.transfer",
"views": [(view.id, "form")],
"view_id": view.id,
"target": "new",
"res_id": wiz.id,
"context": self.env.context,
}
| 34.435897 | 1,343 |
688 | py | PYTHON | 15.0 | # Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock batch picking extended account sale type",
"summary": "Generates invoices when batch is set to Done state",
"version": "15.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["ernestotejeda"],
"development_status": "Beta",
"category": "Warehouse Management",
"depends": ["stock_picking_batch_extended_account", "sale_order_type"],
"website": "https://github.com/OCA/stock-logistics-workflow",
"data": ["views/sale_order_type_views.xml"],
"installable": True,
"license": "AGPL-3",
}
| 40.470588 | 688 |
1,463 | py | PYTHON | 15.0 | # Copyright 2019 Sergio Teruel - Tecnativa <sergio.teruel@tecnativa.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.addons.stock_picking_batch_extended_account.tests import (
test_stock_picking_batch_extended_account as test_bp_account,
)
class TestStockPickingBatchExtendedAccountSaleType(
test_bp_account.TestStockPickingBatchExtendedAccount
):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.sale_type = cls.env["sale.order.type"].create(
{"name": "sale type for tests", "batch_picking_auto_invoice": True}
)
cls.partner.write(
{"sale_type": cls.sale_type.id, "batch_picking_auto_invoice": "no"}
)
cls.partner2.write(
{"sale_type": cls.sale_type.id, "batch_picking_auto_invoice": "sale_type"}
)
def test_create_invoice_from_bp_sale_type(self):
self.order1 = self._create_sale_order(self.partner)
self.order2 = self._create_sale_order(self.partner2)
self.order1.action_confirm()
self.order2.action_confirm()
pickings = self.order1.picking_ids + self.order2.picking_ids
move_lines = pickings.mapped("move_line_ids")
move_lines.qty_done = 1.0
bp = self._create_batch_picking(pickings)
bp.action_assign()
bp.action_done()
self.assertFalse(self.order1.invoice_ids)
self.assertTrue(self.order2.invoice_ids)
| 40.638889 | 1,463 |
263 | py | PYTHON | 15.0 | # Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class SaleOrderType(models.Model):
_inherit = "sale.order.type"
batch_picking_auto_invoice = fields.Boolean()
| 26.3 | 263 |
530 | py | PYTHON | 15.0 | # Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class StockBatchPicking(models.Model):
_inherit = "stock.picking.batch"
def _get_domain_picking_to_invoice(self):
domain = super()._get_domain_picking_to_invoice()
return [
"|",
"&",
("partner_id.batch_picking_auto_invoice", "=", "sale_type"),
("sale_id.type_id.batch_picking_auto_invoice", "=", True),
] + domain
| 33.125 | 530 |
317 | py | PYTHON | 15.0 | # Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
batch_picking_auto_invoice = fields.Selection(
selection_add=[("sale_type", "By sale type")]
)
| 26.416667 | 317 |
671 | py | PYTHON | 15.0 | # Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock batch picking account",
"summary": "Generates invoices when batch is set to Done state",
"version": "15.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["ernestotejeda"],
"development_status": "Beta",
"category": "Warehouse Management",
"depends": ["stock_picking_batch_extended"],
"website": "https://github.com/OCA/stock-logistics-workflow",
"data": ["views/stock_batch_picking.xml", "views/res_partner_views.xml"],
"installable": True,
"license": "AGPL-3",
}
| 39.470588 | 671 |
4,324 | py | PYTHON | 15.0 | # Copyright 2022 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tests import Form, TransactionCase
class TestStockPickingBatchExtendedAccount(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.SaleOrder = cls.env["sale.order"]
cls.product_uom_id = cls.env.ref("uom.product_uom_unit")
cls.stock_loc = cls.browse_ref(cls, "stock.stock_location_stock")
cls.product = cls.env["product.product"].create(
{
"name": "test",
"type": "product",
"list_price": 20.00,
"invoice_policy": "delivery",
}
)
cls.env["stock.quant"].create(
{
"product_id": cls.product.id,
"product_uom_id": cls.product.uom_id.id,
"location_id": cls.stock_loc.id,
"quantity": 100.0,
}
)
cls.partner = cls.env["res.partner"].create(
{"name": "partner test 1", "batch_picking_auto_invoice": "no"}
)
cls.partner2 = cls.env["res.partner"].create(
{"name": "partner test 2", "batch_picking_auto_invoice": "no"}
)
# Use OCA batch picking extended
cls.env.company.use_oca_batch_validation = True
def _create_sale_order(self, partner):
with Form(self.env["sale.order"]) as so_form:
so_form.partner_id = partner
with so_form.order_line.new() as line_form:
line_form.product_id = self.product
line_form.product_uom_qty = 1.0
return so_form.save()
def _create_batch_picking(self, pickings):
# Create the BP
with Form(
self.env["stock.picking.to.batch"].with_context(
active_ids=pickings.ids, active_model="sotck.picking"
)
) as wiz_form:
wiz_form.name = "BP for test"
wiz_form.mode = "new"
wiz = wiz_form.save()
action = wiz.action_create_batch()
return self.env["stock.picking.batch"].browse(action["res_id"])
def _test_create_invoice_from_bp_no_invoices(self):
self.partner.batch_picking_auto_invoice = "no"
self.partner2.batch_picking_auto_invoice = "no"
self.order1 = self._create_sale_order(self.partner)
self.order2 = self._create_sale_order(self.partner2)
self.order1.action_confirm()
self.order2.action_confirm()
pickings = self.order1.picking_ids + self.order2.picking_ids
move_lines = pickings.mapped("move_line_ids")
move_lines.qty_done = 1.0
bp = self._create_batch_picking(pickings)
bp.action_assign()
bp.action_done()
self.assertFalse(self.order1.invoice_ids)
self.assertFalse(self.order2.invoice_ids)
def test_create_invoice_from_bp_all_invoices(self):
self.partner.batch_picking_auto_invoice = "yes"
self.partner2.batch_picking_auto_invoice = "yes"
self.order1 = self._create_sale_order(self.partner)
self.order2 = self._create_sale_order(self.partner2)
self.order1.action_confirm()
self.order2.action_confirm()
pickings = self.order1.picking_ids + self.order2.picking_ids
move_lines = pickings.mapped("move_line_ids")
move_lines.qty_done = 1.0
bp = self._create_batch_picking(pickings)
bp.action_assign()
bp.action_done()
self.assertTrue(self.order1.invoice_ids)
self.assertTrue(self.order2.invoice_ids)
def test_create_invoice_from_bp_mixin(self):
self.partner.batch_picking_auto_invoice = "yes"
self.partner2.batch_picking_auto_invoice = "no"
self.order1 = self._create_sale_order(self.partner)
self.order2 = self._create_sale_order(self.partner2)
self.order1.action_confirm()
self.order2.action_confirm()
pickings = self.order1.picking_ids + self.order2.picking_ids
move_lines = pickings.mapped("move_line_ids")
move_lines.qty_done = 1.0
bp = self._create_batch_picking(pickings)
bp.action_assign()
bp.action_done()
self.assertTrue(self.order1.invoice_ids)
self.assertFalse(self.order2.invoice_ids)
| 41.180952 | 4,324 |
1,016 | py | PYTHON | 15.0 | # Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class StockPicking(models.Model):
_inherit = "stock.picking"
def _action_done(self):
result = super()._action_done()
picking_to_invoice_ids = self.env.context.get(
"picking_to_invoice_in_batch",
)
if not picking_to_invoice_ids:
return result
sales = self.filtered(lambda r: r.id in picking_to_invoice_ids).mapped(
"sale_id"
)
sales_to_invoice = sales.filtered(lambda so: so.invoice_status == "to invoice")
if not sales_to_invoice:
return result
self.env["sale.advance.payment.inv"].create({}).with_context(
active_model="sale.order", active_ids=sales_to_invoice.ids
).create_invoices()
sales_to_invoice.mapped("invoice_ids").filtered(
lambda r: r.state == "draft",
).action_post()
return result
| 35.034483 | 1,016 |
1,085 | py | PYTHON | 15.0 | # Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, models
from odoo.exceptions import UserError
class StockBatchPicking(models.Model):
_inherit = "stock.picking.batch"
def action_print_invoices(self):
invoices = self.mapped("picking_ids.sale_id.invoice_ids")
if not invoices:
raise UserError(_("Nothing to print."))
report = self.env.ref("account.account_invoices_without_payment")
return report.report_action(invoices)
def _get_domain_picking_to_invoice(self):
return [("partner_id.batch_picking_auto_invoice", "=", "yes")]
def _get_self_with_context_to_invoice(self):
to_invoice = self.mapped("picking_ids").filtered_domain(
self._get_domain_picking_to_invoice()
)
return self.with_context(picking_to_invoice_in_batch=to_invoice.ids)
def action_done(self):
self_with_ctx = self._get_self_with_context_to_invoice()
return super(StockBatchPicking, self_with_ctx).action_done()
| 38.75 | 1,085 |
490 | py | PYTHON | 15.0 | # Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
batch_picking_auto_invoice = fields.Selection(
[("yes", "Yes"), ("no", "No")], default="no", company_dependent=True
)
@api.model
def _commercial_fields(self):
res = super()._commercial_fields()
return res + ["batch_picking_auto_invoice"]
| 28.823529 | 490 |
527 | py | PYTHON | 15.0 | # Copyright 2017 ACSONE SA/NV
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Stock Move Line Auto Fill",
"summary": "Stock Move Line auto fill",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock"],
"data": ["views/stock_picking.xml", "views/stock_picking_type_views.xml"],
}
| 37.642857 | 527 |
19,523 | py | PYTHON | 15.0 | # Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import UserError
from odoo.tests import Form, common
@common.tagged("-at_install", "post_install")
class TestStockPicking(common.TransactionCase):
def setUp(self):
super(TestStockPicking, self).setUp()
# models
self.picking_model = self.env["stock.picking"]
self.move_model = self.env["stock.move"]
# warehouse and picking types
self.warehouse = self.env.ref("stock.stock_warehouse_shop0")
self.picking_type_in = self.env.ref("stock.chi_picking_type_in")
self.picking_type_out = self.env.ref("stock.chi_picking_type_out")
self.supplier_location = self.env.ref("stock.stock_location_suppliers")
self.customer_location = self.env.ref("stock.stock_location_customers")
# Allow all companies for OdooBot user and set default user company
# to warehouse company
companies = self.env["res.company"].search([])
self.env.user.company_ids = [(6, 0, companies.ids)]
self.env.user.company_id = self.warehouse.company_id
# products
self.product_8 = self.env.ref("product.product_product_8")
self.product_9 = self.env.ref("product.product_product_9")
self.product_10 = self.env.ref("product.product_product_10")
self.product_11 = self.env.ref("product.product_product_11")
self.product_12 = self.env.ref("product.product_product_12")
# supplier
self.supplier = self.env.ref("base.res_partner_1")
# customer
self.customer = self.env.ref("base.res_partner_12")
self.picking = self.picking_model.with_context(
default_picking_type_id=self.picking_type_in.id
).create(
{
"partner_id": self.supplier.id,
"picking_type_id": self.picking_type_in.id,
"location_id": self.supplier_location.id,
}
)
self.picking_out = self.picking_model.with_context(
default_picking_type_id=self.picking_type_out.id
).create(
{
"partner_id": self.customer.id,
"picking_type_id": self.picking_type_out.id,
"location_id": self.picking_type_out.default_location_src_id.id,
"location_dest_id": self.customer_location.id,
}
)
self.dozen = self.env.ref("uom.product_uom_dozen")
def test_compute_action_pack_operation_auto_fill_allowed(self):
self.move_model.create(
dict(
product_id=self.product_9.id,
picking_id=self.picking.id,
name=self.product_9.display_name,
picking_type_id=self.picking_type_in.id,
product_uom_qty=1.0,
location_id=self.supplier_location.id,
location_dest_id=self.picking_type_in.default_location_dest_id.id,
product_uom=self.product_9.uom_id.id,
)
)
# the auto fill action isn't available when picking is in draft
# state.
self.assertEqual(self.picking.state, "draft")
self.assertFalse(self.picking.action_pack_op_auto_fill_allowed)
# the auto fill action isn't available if no pack operation is
# created.
self.picking.state = "assigned"
self.assertFalse(self.picking.action_pack_op_auto_fill_allowed)
# The auto fill action is available when picking is assigned and
# the picking have already pack operations.
self.picking.action_confirm()
self.assertTrue(self.picking.action_pack_op_auto_fill_allowed)
def test_check_action_pack_operation_auto_fill_allowed(self):
self.move_model.create(
dict(
product_id=self.product_9.id,
picking_id=self.picking.id,
name=self.product_9.display_name,
picking_type_id=self.picking_type_in.id,
product_uom_qty=1.0,
location_id=self.supplier_location.id,
location_dest_id=self.picking_type_in.default_location_dest_id.id,
product_uom=self.product_9.uom_id.id,
)
)
# the auto fill action isn't available when picking is in draft
# state.
self.assertEqual(self.picking.state, "draft")
with self.cr.savepoint(), self.assertRaises(UserError):
self.picking.action_pack_operation_auto_fill()
# the auto fill action isn't available if no pack operation is
# created.
self.picking.state = "assigned"
with self.cr.savepoint(), self.assertRaises(UserError):
self.picking.action_pack_operation_auto_fill()
# The auto fill action is available when picking is assigned and
# the picking have already pack operations.
self.picking.action_confirm()
self.picking.action_pack_operation_auto_fill()
def test_action_pack_operation_auto_fill(self):
# set tracking on the products
self.picking_type_in.use_create_lots = True
self.product_8.tracking = "lot"
self.product_9.tracking = "none"
self.product_10.tracking = "serial"
self.product_11.tracking = "none"
self.move_model.create(
dict(
product_id=self.product_8.id,
picking_id=self.picking.id,
name=self.product_8.display_name,
picking_type_id=self.picking_type_in.id,
product_uom_qty=1.0,
location_id=self.supplier_location.id,
location_dest_id=self.picking_type_in.default_location_dest_id.id,
product_uom=self.product_8.uom_id.id,
)
)
self.move_model.create(
dict(
product_id=self.product_9.id,
picking_id=self.picking.id,
name=self.product_9.display_name,
picking_type_id=self.picking_type_in.id,
product_uom_qty=1.0,
location_id=self.supplier_location.id,
location_dest_id=self.picking_type_in.default_location_dest_id.id,
product_uom=self.product_9.uom_id.id,
)
)
self.move_model.create(
dict(
product_id=self.product_10.id,
picking_id=self.picking.id,
name=self.product_10.display_name,
picking_type_id=self.picking_type_in.id,
product_uom_qty=1.0,
location_id=self.supplier_location.id,
location_dest_id=self.picking_type_in.default_location_dest_id.id,
product_uom=self.product_10.uom_id.id,
)
)
self.move_model.create(
dict(
product_id=self.product_11.id,
picking_id=self.picking.id,
name=self.product_11.display_name + " pack",
picking_type_id=self.picking_type_in.id,
product_uom_qty=1.0,
location_id=self.supplier_location.id,
location_dest_id=self.picking_type_in.default_location_dest_id.id,
product_uom=self.product_11.uom_id.id,
)
)
self.move_model.create(
dict(
product_id=self.product_12.id,
picking_id=self.picking.id,
name=self.product_12.display_name,
picking_type_id=self.picking_type_in.id,
product_uom_qty=1.0,
location_id=self.supplier_location.id,
location_dest_id=self.picking_type_in.default_location_dest_id.id,
product_uom=self.dozen.id,
)
)
self.picking.action_confirm()
self.assertEqual(self.picking.state, "assigned")
self.assertEqual(len(self.picking.move_line_ids), 5)
# At this point for each move we have an operation created.
product_8_op = self.picking.move_line_ids.filtered(
lambda p: p.product_id == self.product_8
)
self.assertTrue(product_8_op)
product_9_op = self.picking.move_line_ids.filtered(
lambda p: p.product_id == self.product_9
)
self.assertTrue(product_9_op)
product_11_op = self.picking.move_line_ids.filtered(
lambda p: p.product_id == self.product_11
)
self.assertTrue(product_11_op)
product_12_op = self.picking.move_line_ids.filtered(
lambda p: p.product_id == self.product_12
)
# replace the product_id with a pack in for the product_11_op
# operation
pack = self.env["stock.quant.package"].create(
{
"quant_ids": [
(
0,
0,
{
"product_id": self.product_11.id,
"quantity": 1,
"location_id": self.supplier_location.id,
"product_uom_id": self.product_11.uom_id.id,
},
)
]
}
)
product_11_op.write({"package_id": pack.id})
product_10_op = self.picking.move_line_ids.filtered(
lambda p: p.product_id == self.product_10
)
self.assertTrue(product_10_op)
# Try to fill all the operation automatically.
# The expected result is only operations with product_id set and
# the product_id.tracking == none, have a qty_done set.
self.picking.action_pack_operation_auto_fill()
self.assertFalse(product_8_op.qty_done)
self.assertEqual(product_9_op.product_uom_qty, product_9_op.qty_done)
self.assertFalse(product_10_op.qty_done)
self.assertEqual(product_11_op.product_uom_qty, product_11_op.qty_done)
self.assertEqual(product_12_op.product_uom_qty, product_12_op.qty_done)
def test_action_auto_transfer(self):
# set tracking on the products
self.picking_type_in.auto_fill_operation = True
self.product_8.tracking = "lot"
self.product_9.tracking = "none"
self.move_model.create(
dict(
product_id=self.product_8.id,
picking_id=self.picking.id,
name=self.product_8.display_name,
picking_type_id=self.picking_type_in.id,
product_uom_qty=1.0,
location_id=self.supplier_location.id,
location_dest_id=self.picking_type_in.default_location_dest_id.id,
product_uom=self.product_8.uom_id.id,
)
)
self.move_model.create(
dict(
product_id=self.product_9.id,
picking_id=self.picking.id,
name=self.product_9.display_name,
picking_type_id=self.picking_type_in.id,
product_uom_qty=1.0,
location_id=self.supplier_location.id,
location_dest_id=self.picking_type_in.default_location_dest_id.id,
product_uom=self.product_9.uom_id.id,
)
)
self.picking.action_assign()
self.assertEqual(self.picking.state, "assigned")
self.assertEqual(len(self.picking.move_line_ids), 2)
# At this point for each move we have an operation created.
product_8_op = self.picking.move_line_ids.filtered(
lambda p: p.product_id == self.product_8
)
self.assertTrue(product_8_op)
product_9_op = self.picking.move_line_ids.filtered(
lambda p: p.product_id == self.product_9
)
self.assertTrue(product_9_op)
# Try to fill all the operation automatically.
# The expected result is only opertions with product_id set and
self.assertTrue(product_8_op.qty_done)
self.assertTrue(product_9_op.qty_done)
def test_action_auto_transfer_avoid_assign_lots(self):
# set tracking on the products
self.picking_type_out.auto_fill_operation = True
self.picking_type_out.avoid_lot_assignment = True
self.product_8.tracking = "lot"
self.product_9.tracking = "none"
self.lot8 = self.env["stock.production.lot"].create(
{
"company_id": self.warehouse.company_id.id,
"product_id": self.product_8.id,
"name": "Lot 1",
}
)
self.quant8 = self.env["stock.quant"].create(
{
"product_id": self.product_8.id,
"location_id": self.picking_out.location_id.id,
"quantity": 6,
"lot_id": self.lot8.id,
}
)
self.quant9 = self.env["stock.quant"].create(
{
"product_id": self.product_9.id,
"location_id": self.picking_out.location_id.id,
"quantity": 10,
}
)
self.move_model.create(
{
"product_id": self.product_8.id,
"picking_id": self.picking_out.id,
"name": self.product_8.display_name,
"picking_type_id": self.picking_type_out.id,
"product_uom_qty": 1.0,
"location_id": self.picking_type_out.default_location_src_id.id,
"location_dest_id": self.customer_location.id,
"product_uom": self.product_8.uom_id.id,
}
)
self.move_model.create(
{
"product_id": self.product_9.id,
"picking_id": self.picking_out.id,
"name": self.product_9.display_name,
"picking_type_id": self.picking_type_out.id,
"product_uom_qty": 10.0,
"location_id": self.picking_type_out.default_location_src_id.id,
"location_dest_id": self.customer_location.id,
"product_uom": self.product_9.uom_id.id,
}
)
self.picking_out.action_confirm()
self.picking_out.action_assign()
self.assertEqual(self.picking_out.state, "assigned")
self.assertEqual(len(self.picking_out.move_line_ids), 2)
# At this point for each move we have an operation created.
product_8_op = self.picking_out.move_line_ids.filtered(
lambda p: p.product_id == self.product_8
)
self.assertTrue(product_8_op)
product_9_op = self.picking_out.move_line_ids.filtered(
lambda p: p.product_id == self.product_9
)
self.assertTrue(product_9_op)
# Try to fill all the operation automatically.
# The expected result is only opertions with product_id set and
self.assertFalse(product_8_op.qty_done)
self.assertTrue(product_9_op.qty_done)
def test_action_assign_replenish_stock(self):
# Covered case:
# For a product with less stock than initial demand, check after
# replenish stock that quantity done is written with initial demand
# after check availability
self.picking_type_in.auto_fill_operation = True
product = self.env["product.product"].create(
{"name": "Test auto fill", "type": "product"}
)
product_quant = self.env["stock.quant"].create(
{
"product_id": product.id,
"location_id": self.picking_type_out.default_location_src_id.id,
"quantity": 1000.00,
}
)
self.move_model.create(
dict(
product_id=product.id,
picking_id=self.picking.id,
name=product.display_name,
picking_type_id=self.picking_type_out.id,
product_uom_qty=1500.00,
location_id=self.picking_type_out.default_location_src_id.id,
location_dest_id=self.customer_location.id,
product_uom=product.uom_id.id,
)
)
self.picking.action_assign()
self.assertEqual(self.picking.state, "assigned")
self.assertEqual(len(self.picking.move_line_ids), 1)
# Try to fill all the operation automatically.
self.assertEqual(self.picking.move_line_ids.qty_done, 1000.00)
product_quant.quantity = 1500.00
self.picking.action_assign()
self.assertEqual(self.picking.move_line_ids.qty_done, 1500.00)
def _picking_return(self, picking, qty):
# Make a return from picking
ReturnWiz = self.env["stock.return.picking"]
return_form = Form(
ReturnWiz.with_context(
active_ids=picking.ids,
active_id=picking.ids[0],
active_model="stock.picking",
)
)
stock_return_picking = return_form.save()
stock_return_picking.product_return_moves.quantity = qty
stock_return_picking_action = stock_return_picking.create_returns()
return_pick = self.env["stock.picking"].browse(
stock_return_picking_action["res_id"]
)
return_pick.action_assign()
# return_pick.move_lines.quantity_done = qty
return_pick._action_done()
return return_pick
def test_return_twice(self):
# Covered case:
# Return more than one times not duplicate quant units in stock
self.picking_type_out.auto_fill_operation = True
# By default from v15 there is a picking operation type to return goods
self.picking_type_out.return_picking_type_id.auto_fill_operation = True
self.picking_type_in.auto_fill_operation = True
product = self.env["product.product"].create(
{"name": "Test return", "type": "product"}
)
self.env["stock.quant"].create(
{
"product_id": product.id,
"location_id": self.picking_type_out.default_location_src_id.id,
"quantity": 500.00,
}
)
self.move_model.create(
dict(
product_id=product.id,
picking_id=self.picking_out.id,
name=product.display_name,
picking_type_id=self.picking_type_out.id,
product_uom_qty=500.00,
location_id=self.picking_type_out.default_location_src_id.id,
location_dest_id=self.customer_location.id,
product_uom=product.uom_id.id,
)
)
self.picking_out.action_confirm()
self.picking_out.action_assign()
# self.picking_out.move_lines.quantity_done = 500
self.picking_out._action_done()
self.assertEqual(product.qty_available, 0.0)
# Make first return from customer location to stock location
returned_picking = self._picking_return(self.picking_out, 500.00)
self.assertEqual(product.qty_available, 500)
# Make second return from stock location to customer location
returned_picking = self._picking_return(returned_picking, 500.00)
self.assertEqual(product.qty_available, 0.0)
# Make third return from customer location to stock location
self._picking_return(returned_picking, 500.00)
self.assertEqual(product.qty_available, 500)
| 39.924335 | 19,523 |
730 | py | PYTHON | 15.0 | # Copyright 2017 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class StockPickingType(models.Model):
_inherit = "stock.picking.type"
auto_fill_operation = fields.Boolean(
string="Auto fill operations",
help="To auto fill done quantity in picking document.\n"
"- If checked, auto fill done quantity automatically\n"
"- If unchecked, show button AutoFill"
" for user to do the auto fill manually",
)
avoid_lot_assignment = fields.Boolean(
string="Avoid auto-assignment of lots",
help="Avoid auto fill for more line with lots product",
default=True,
)
| 34.761905 | 730 |
2,150 | py | PYTHON | 15.0 | # Copyright 2017 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# Copyright 2018 David Vidal <david.vidal@tecnativa.com>
# Copyright 2020 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class StockMove(models.Model):
_inherit = "stock.move"
def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
"""
Auto-assign as done the quantity proposed for the lots.
Keep this method to avoid extra write after picking _action_assign
"""
self.ensure_one()
res = super()._prepare_move_line_vals(quantity, reserved_quant)
if not self.picking_id.auto_fill_operation:
return res
elif self.picking_id.picking_type_id.avoid_lot_assignment and res.get("lot_id"):
return res
if self.quantity_done != self.product_uom_qty:
# Not assign qty_done for extra moves in over processed quantities
res.update({"qty_done": res.get("product_uom_qty", 0.0)})
return res
def _action_assign(self):
"""
Update stock move line quantity done field with reserved quantity.
This method take into account incoming and outgoing moves.
We can not use _prepare_move_line_vals method because this method only
is called for a new lines.
"""
res = super()._action_assign()
for line in self.filtered(
lambda m: m.state
in ["confirmed", "assigned", "waiting", "partially_available"]
):
if (
line._should_bypass_reservation()
or not line.picking_id.auto_fill_operation
):
return res
lines_to_update = line.move_line_ids.filtered(
lambda l: l.qty_done != l.product_uom_qty
)
for move_line in lines_to_update:
if (
not line.picking_id.picking_type_id.avoid_lot_assignment
or not move_line.lot_id
):
move_line.qty_done = move_line.product_uom_qty
return res
| 39.814815 | 2,150 |
2,236 | py | PYTHON | 15.0 | # Copyright 2017 ACSONE SA/NV
# Copyright 2018 JARSA Sistemas S.A. de C.V.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class StockPicking(models.Model):
_inherit = "stock.picking"
action_pack_op_auto_fill_allowed = fields.Boolean(
compute="_compute_action_pack_operation_auto_fill_allowed"
)
auto_fill_operation = fields.Boolean(
string="Auto fill operations",
related="picking_type_id.auto_fill_operation",
)
@api.depends("state", "move_line_ids")
def _compute_action_pack_operation_auto_fill_allowed(self):
"""
The auto fill button is allowed only in ready state, and the
picking have pack operations.
"""
for rec in self:
rec.action_pack_op_auto_fill_allowed = (
rec.state == "assigned" and rec.move_line_ids
)
def _check_action_pack_operation_auto_fill_allowed(self):
if any(not r.action_pack_op_auto_fill_allowed for r in self):
raise UserError(
_(
"Filling the operations automatically is not possible, "
"perhaps the pickings aren't in the right state "
"(Partially available or available)."
)
)
def action_pack_operation_auto_fill(self):
"""
Fill automatically pack operation for products with the following
conditions:
- the package is not required, the package is required if the
the no product is set on the operation.
- the operation has no qty_done yet.
"""
self._check_action_pack_operation_auto_fill_allowed()
operations = self.mapped("move_line_ids")
operations_to_auto_fill = operations.filtered(
lambda op: (
op.product_id
and not op.qty_done
and (
not op.lots_visible
or not op.picking_id.picking_type_id.avoid_lot_assignment
)
)
)
for op in operations_to_auto_fill:
op.qty_done = op.product_uom_qty
| 36.064516 | 2,236 |
918 | py | PYTHON | 15.0 | # Copyright 2013-17 Agile Business Group (<http://www.agilebg.com>)
# Copyright 2016 AvanzOSC (<http://www.avanzosc.es>)
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# Copyright 2017 Jacques-Etienne Baudoux <je@bcim.be>
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
"name": "Stock Picking Invoice Link",
"version": "15.0.1.0.3",
"development_status": "Production/Stable",
"category": "Warehouse Management",
"summary": "Adds link between pickings and invoices",
"author": "Agile Business Group, "
"Tecnativa, "
"BCIM sprl, "
"Softdil S.L, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"license": "AGPL-3",
"depends": ["sale_stock"],
"data": ["views/stock_view.xml", "views/account_invoice_view.xml"],
"installable": True,
}
| 38.208333 | 917 |
16,118 | py | PYTHON | 15.0 | # Copyright 2016 Oihane Crucelaegui - AvanzOSC
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# Copyright 2017 Jacques-Etienne Baudoux <je@bcim.be>
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.exceptions import UserError
from odoo.tests import Form, tagged
from odoo.addons.sale.tests.common import TestSaleCommon
@tagged("post_install", "-at_install")
class TestStockPickingInvoiceLink(TestSaleCommon):
@classmethod
def _update_product_qty(cls, product):
product_qty = cls.env["stock.change.product.qty"].create(
{
"product_id": product.id,
"product_tmpl_id": product.product_tmpl_id.id,
"new_quantity": 100.0,
}
)
product_qty.change_product_qty()
return product_qty
@classmethod
def _create_sale_order_and_confirm(cls):
so = cls.env["sale.order"].create(
{
"partner_id": cls.partner_a.id,
"partner_invoice_id": cls.partner_a.id,
"partner_shipping_id": cls.partner_a.id,
"order_line": [
(
0,
0,
{
"name": cls.prod_order.name,
"product_id": cls.prod_order.id,
"product_uom_qty": 2,
"product_uom": cls.prod_order.uom_id.id,
"price_unit": cls.prod_order.list_price,
},
),
(
0,
0,
{
"name": cls.prod_del.name,
"product_id": cls.prod_del.id,
"product_uom_qty": 2,
"product_uom": cls.prod_del.uom_id.id,
"price_unit": cls.prod_del.list_price,
},
),
(
0,
0,
{
"name": cls.serv_order.name,
"product_id": cls.serv_order.id,
"product_uom_qty": 2,
"product_uom": cls.serv_order.uom_id.id,
"price_unit": cls.serv_order.list_price,
},
),
],
"pricelist_id": cls.env.ref("product.list0").id,
"picking_policy": "direct",
}
)
so.action_confirm()
return so
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
for (_, i) in cls.company_data.items():
if "type" in i and i.type == "product":
cls._update_product_qty(i)
cls.prod_order = cls.company_data["product_order_no"]
cls.prod_order.invoice_policy = "delivery"
cls.prod_del = cls.company_data["product_delivery_no"]
cls.prod_del.invoice_policy = "delivery"
cls.serv_order = cls.company_data["product_service_order"]
cls.so = cls._create_sale_order_and_confirm()
def test_00_sale_stock_invoice_link(self):
pick_obj = self.env["stock.picking"]
# invoice on order
self.so._create_invoices()
# deliver partially
self.assertEqual(
self.so.invoice_status,
"no",
"Sale Stock: so invoice_status should be "
'"nothing to invoice" after invoicing',
)
pick_1 = self.so.picking_ids.filtered(
lambda x: x.picking_type_code == "outgoing"
and x.state in ("confirmed", "assigned", "partially_available")
)
pick_1.move_line_ids.write({"qty_done": 1})
pick_1._action_done()
self.assertEqual(
self.so.invoice_status,
"to invoice",
"Sale Stock: so invoice_status should be "
'"to invoice" after partial delivery',
)
inv_1 = self.so._create_invoices()
# complete the delivery
self.assertEqual(
self.so.invoice_status,
"no",
"Sale Stock: so invoice_status should be "
'"nothing to invoice" after partial delivery '
"and invoicing",
)
self.assertEqual(
len(self.so.picking_ids), 2, "Sale Stock: number of pickings should be 2"
)
pick_2 = self.so.picking_ids.filtered(
lambda x: x.picking_type_code == "outgoing"
and x.state in ("confirmed", "assigned", "partially_available")
)
pick_2.move_line_ids.write({"qty_done": 1})
pick_2._action_done()
backorders = pick_obj.search([("backorder_id", "=", pick_2.id)])
self.assertFalse(
backorders,
"Sale Stock: second picking should be "
"final without need for a backorder",
)
self.assertEqual(
self.so.invoice_status,
"to invoice",
"Sale Stock: so invoice_status should be "
'"to invoice" after complete delivery',
)
inv_2 = self.so._create_invoices()
self.assertEqual(
self.so.invoice_status,
"invoiced",
"Sale Stock: so invoice_status should be "
'"fully invoiced" after complete delivery and '
"invoicing",
)
# Check links
self.assertEqual(
inv_1.picking_ids,
pick_1,
"Invoice 1 must link to only First Partial Delivery",
)
self.assertEqual(
inv_1.invoice_line_ids.mapped("move_line_ids"),
pick_1.move_lines.filtered(
lambda x: x.product_id.invoice_policy == "delivery"
),
"Invoice 1 lines must link to only First Partial Delivery lines",
)
self.assertEqual(
inv_2.picking_ids, pick_2, "Invoice 2 must link to only Second Delivery"
)
self.assertEqual(
inv_2.invoice_line_ids.mapped("move_line_ids"),
pick_2.move_lines.filtered(
lambda x: x.product_id.invoice_policy == "delivery"
),
"Invoice 2 lines must link to only Second Delivery lines",
)
# Invoice view
result = pick_1.action_view_invoice()
self.assertEqual(result["views"][0][1], "form")
self.assertEqual(result["res_id"], inv_1.id)
# Mock multiple invoices linked to a picking
inv_3 = inv_1.copy()
inv_3.picking_ids |= pick_1
result = pick_1.action_view_invoice()
self.assertEqual(result["views"][0][1], "tree")
# Cancel invoice and invoice
inv_1.button_cancel()
self.so._create_invoices()
self.assertEqual(
inv_1.picking_ids,
pick_1,
"Invoice 1 must link to only First Partial Delivery",
)
self.assertEqual(
inv_1.invoice_line_ids.mapped("move_line_ids"),
pick_1.move_lines.filtered(
lambda x: x.product_id.invoice_policy == "delivery"
),
"Invoice 1 lines must link to only First Partial Delivery lines",
)
# Try to update a picking move which has a invoice line linked
with self.assertRaises(UserError):
pick_1.move_line_ids.write({"qty_done": 20.0})
def test_return_picking_to_refund(self):
pick_1 = self.so.picking_ids.filtered(
lambda x: x.picking_type_code == "outgoing"
and x.state in ("confirmed", "assigned", "partially_available")
)
pick_1.move_line_ids.write({"qty_done": 2})
pick_1._action_done()
# Create invoice
inv = self.so._create_invoices()
inv_line_prod_del = inv.invoice_line_ids.filtered(
lambda l: l.product_id == self.prod_del
)
self.assertEqual(
inv_line_prod_del.move_line_ids,
pick_1.move_lines.filtered(lambda m: m.product_id == self.prod_del),
)
# Create return picking
return_form = Form(self.env["stock.return.picking"])
return_form.picking_id = pick_1
return_wiz = return_form.save()
# Remove product ordered line
return_wiz.product_return_moves.filtered(
lambda l: l.product_id == self.prod_order
).unlink()
return_wiz.product_return_moves.quantity = 1.0
return_wiz.product_return_moves.to_refund = True
res = return_wiz.create_returns()
return_pick = self.env["stock.picking"].browse(res["res_id"])
# Validate picking
return_pick.move_lines.quantity_done = 1.0
return_pick.button_validate()
inv = self.so._create_invoices(final=True)
inv_line_prod_del = inv.invoice_line_ids.filtered(
lambda l: l.product_id == self.prod_del
)
self.assertEqual(inv_line_prod_del.move_line_ids, return_pick.move_lines)
def test_invoice_refund(self):
pick_1 = self.so.picking_ids.filtered(
lambda x: x.picking_type_code == "outgoing"
and x.state in ("confirmed", "assigned", "partially_available")
)
pick_1.move_line_ids.write({"qty_done": 2})
pick_1._action_done()
# Create invoice
inv = self.so._create_invoices()
inv.action_post()
move_line_prod_del = pick_1.move_lines.filtered(
lambda l: l.product_id == self.prod_del
)
wiz_invoice_refund = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=inv.ids)
.create(
{
"refund_method": "modify",
"reason": "test",
"journal_id": inv.journal_id.id,
}
)
)
wiz_invoice_refund.reverse_moves()
new_invoice = self.so.invoice_ids.filtered(
lambda i: i.move_type == "out_invoice" and i.state == "draft"
)
inv_line_prod_del = new_invoice.invoice_line_ids.filtered(
lambda l: l.product_id == self.prod_del
)
self.assertEqual(move_line_prod_del, inv_line_prod_del.move_line_ids)
# Test action open picking from an invoice
res = new_invoice.action_show_picking()
opened_picking = self.env["stock.picking"].browse(res["res_id"])
self.assertEqual(pick_1, opened_picking)
def test_invoice_refund_invoice(self):
"""Check that the invoice created after a refund is linked to the stock
picking.
"""
pick_1 = self.so.picking_ids.filtered(
lambda x: x.picking_type_code == "outgoing"
and x.state in ("confirmed", "assigned", "partially_available")
)
pick_1.move_line_ids.write({"qty_done": 2})
pick_1._action_done()
# Create invoice
inv = self.so._create_invoices()
inv.action_post()
# Refund invoice
wiz_invoice_refund = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=inv.ids)
.create(
{
"refund_method": "cancel",
"reason": "test",
"journal_id": inv.journal_id.id,
}
)
)
wiz_invoice_refund.reverse_moves()
# Create invoice again
new_inv = self.so._create_invoices()
new_inv.action_post()
# Assert that new invoice has related picking
self.assertEqual(new_inv.picking_ids, pick_1)
def test_partial_invoice_full_link(self):
"""Check that the partial invoices are linked to the stock
picking.
"""
pick_1 = self.so.picking_ids.filtered(
lambda x: x.picking_type_code == "outgoing"
and x.state in ("confirmed", "assigned", "partially_available")
)
pick_1.move_line_ids.write({"qty_done": 2})
pick_1._action_done()
# Create invoice
inv = self.so._create_invoices()
with Form(inv) as move_form:
for i in range(len(move_form.invoice_line_ids)):
with move_form.invoice_line_ids.edit(i) as line_form:
line_form.quantity = 1
inv.action_post()
self.assertEqual(inv.picking_ids, pick_1)
inv2 = self.so._create_invoices()
self.assertEqual(inv2.picking_ids, pick_1)
def test_return_and_invoice_refund(self):
pick_1 = self.so.picking_ids.filtered(
lambda x: x.picking_type_code == "outgoing"
and x.state in ("confirmed", "assigned", "partially_available")
)
pick_1.move_line_ids.write({"qty_done": 2})
pick_1._action_done()
# Create invoice
inv = self.so._create_invoices()
inv_line_prod_del = inv.invoice_line_ids.filtered(
lambda l: l.product_id == self.prod_del
)
inv.action_post()
self.assertEqual(
inv_line_prod_del.move_line_ids,
pick_1.move_lines.filtered(lambda m: m.product_id == self.prod_del),
)
# Create return picking
return_form = Form(self.env["stock.return.picking"])
return_form.picking_id = pick_1
return_wiz = return_form.save()
# Remove product ordered line
return_wiz.product_return_moves.filtered(
lambda l: l.product_id == self.prod_order
).unlink()
return_wiz.product_return_moves.quantity = 1.0
return_wiz.product_return_moves.to_refund = True
res = return_wiz.create_returns()
return_pick = self.env["stock.picking"].browse(res["res_id"])
# Validate picking
return_pick.move_lines.quantity_done = 1.0
return_pick.button_validate()
wiz_invoice_refund = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=inv.ids)
.create(
{
"refund_method": "cancel",
"reason": "test",
"journal_id": inv.journal_id.id,
}
)
)
action = wiz_invoice_refund.reverse_moves()
invoice_refund = self.env["account.move"].browse(action["res_id"])
inv_line_prod_del_refund = invoice_refund.invoice_line_ids.filtered(
lambda l: l.product_id == self.prod_del
)
self.assertEqual(
inv_line_prod_del_refund.move_line_ids,
return_pick.move_lines.filtered(lambda m: m.product_id == self.prod_del),
)
def test_link_transfer_after_invoice_creation(self):
self.prod_order.invoice_policy = "order"
# Create new sale.order to get the change on invoice policy
so = self._create_sale_order_and_confirm()
# create and post invoice
invoice = so._create_invoices()
# Validate shipment
picking = so.picking_ids.filtered(
lambda x: x.picking_type_code == "outgoing"
and x.state in ("confirmed", "assigned")
)
picking.move_line_ids.write({"qty_done": 2})
picking._action_done()
# Two invoice lines has been created, One of them related to product service
self.assertEqual(len(invoice.invoice_line_ids), 2)
line = invoice.invoice_line_ids
# Move lines are set in invoice lines
self.assertEqual(len(line.mapped("move_line_ids")), 1)
# One of the lines has invoice_policy = 'order' but the other one not
self.assertIn(line.mapped("move_line_ids"), picking.move_lines)
self.assertEqual(len(invoice.picking_ids), 1)
# Invoices are set in pickings
self.assertEqual(picking.invoice_ids, invoice)
| 39.502451 | 16,117 |
3,713 | py | PYTHON | 15.0 | # Copyright 2013-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright 2015-2016 AvanzOSC
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# Copyright 2017 Jacques-Etienne Baudoux <je@bcim.be>
# Copyright 2020 Manuel Calero - Tecnativa
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from collections import defaultdict
from odoo import api, fields, models
class AccountMove(models.Model):
_inherit = "account.move"
picking_ids = fields.Many2many(
comodel_name="stock.picking",
string="Related Pickings",
store=True,
compute="_compute_picking_ids",
help="Related pickings (only when the invoice has been generated from a sale order).",
)
delivery_count = fields.Integer(
string="Delivery Orders", compute="_compute_picking_ids", store=True
)
@api.depends("invoice_line_ids", "invoice_line_ids.move_line_ids")
def _compute_picking_ids(self):
for invoice in self:
invoice.picking_ids = invoice.mapped(
"invoice_line_ids.move_line_ids.picking_id"
)
invoice.delivery_count = len(invoice.picking_ids)
def action_show_picking(self):
"""This function returns an action that display existing pickings
of given invoice.
It can either be a in a list or in a form view, if there is only
one picking to show.
"""
self.ensure_one()
form_view_name = "stock.view_picking_form"
result = self.env["ir.actions.act_window"]._for_xml_id(
"stock.action_picking_tree_all"
)
if len(self.picking_ids) > 1:
result["domain"] = "[('id', 'in', %s)]" % self.picking_ids.ids
else:
form_view = self.env.ref(form_view_name)
result["views"] = [(form_view.id, "form")]
result["res_id"] = self.picking_ids.id
return result
def _reverse_move_vals(self, default_values, cancel=True):
move_vals = super()._reverse_move_vals(default_values, cancel=cancel)
product_dic = defaultdict(int)
# Invoice returned moves marked as to_refund
for line_command in move_vals.get("line_ids", []):
line_vals = line_command[2]
product_id = line_vals.get("product_id", False)
if product_id:
position = product_dic[product_id]
product_line = self.line_ids.filtered(
lambda l: l.product_id.id == product_id
)[position]
product_dic[product_id] += 1
stock_moves = product_line.mapped("move_line_ids")
if stock_moves:
line_vals["move_line_ids"] = [(4, m.id) for m in stock_moves]
return move_vals
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
move_line_ids = fields.Many2many(
comodel_name="stock.move",
relation="stock_move_invoice_line_rel",
column1="invoice_line_id",
column2="move_id",
string="Related Stock Moves",
readonly=True,
copy=False,
help="Related stock moves (only when the invoice has been"
" generated from a sale order).",
)
def copy_data(self, default=None):
"""Copy the move_line_ids in case of refund invoice creating a new invoice
(refund_method="modify").
"""
self.ensure_one()
res = super().copy_data(default=default)
if (
self.env.context.get("force_copy_stock_moves")
and "move_line_ids" not in res
):
res[0]["move_line_ids"] = [(6, 0, self.move_line_ids.ids)]
return res
| 37.13 | 3,713 |
2,320 | py | PYTHON | 15.0 | # Copyright 2013-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright 2017 Jacques-Etienne Baudoux <je@bcim.be>
# Copyright 2021 Tecnativa - João Marques
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import models
from odoo.tools import float_compare, float_is_zero
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
def get_stock_moves_link_invoice(self):
moves_linked = self.env["stock.move"]
to_invoice = self.qty_to_invoice
for stock_move in self.move_ids.filtered(lambda sm: sm.state == "done").sorted(
lambda m: (m.write_date, m.id), reverse=True
):
if (
stock_move.state != "done"
or stock_move.scrapped
or (
stock_move.location_dest_id.usage != "customer"
and (
stock_move.location_id.usage != "customer"
or not stock_move.to_refund
)
)
):
continue
if not stock_move.invoice_line_ids:
to_invoice -= (
stock_move.quantity_done
if not stock_move.to_refund
else -stock_move.quantity_done
)
moves_linked += stock_move
continue
elif float_is_zero(
to_invoice, precision_rounding=self.product_uom.rounding
):
break
to_invoice -= (
stock_move.quantity_done
if not stock_move.to_refund
else -stock_move.quantity_done
)
moves_linked += stock_move
return moves_linked
def _prepare_invoice_line(self, **optional_values):
vals = super()._prepare_invoice_line(**optional_values)
stock_moves = self.get_stock_moves_link_invoice()
# Invoice returned moves marked as to_refund
if (
float_compare(
self.qty_to_invoice, 0.0, precision_rounding=self.currency_id.rounding
)
< 0
):
stock_moves = stock_moves.filtered("to_refund")
vals["move_line_ids"] = [(4, m.id) for m in stock_moves]
return vals
| 37.403226 | 2,319 |
2,501 | py | PYTHON | 15.0 | # Copyright 2013-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright 2015-2016 AvanzOSC
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import _, fields, models
from odoo.exceptions import UserError
class StockMove(models.Model):
_inherit = "stock.move"
invoice_line_ids = fields.Many2many(
comodel_name="account.move.line",
relation="stock_move_invoice_line_rel",
column1="move_id",
column2="invoice_line_id",
string="Invoice Line",
copy=False,
readonly=True,
)
def write(self, vals):
"""
User can update any picking in done state, but if this picking already
invoiced the stock move done quantities can be different to invoice
line quantities. So to avoid this inconsistency you can not update any
stock move line in done state and have invoice lines linked.
"""
if "product_uom_qty" in vals and not self.env.context.get(
"bypass_stock_move_update_restriction"
):
for move in self:
if move.state == "done" and move.invoice_line_ids:
raise UserError(_("You can not modify an invoiced stock move"))
res = super().write(vals)
if vals.get("state", "") == "done":
stock_moves = self.get_moves_delivery_link_invoice()
for stock_move in stock_moves.filtered(
lambda sm: sm.sale_line_id and sm.product_id.invoice_policy == "order"
):
inv_type = stock_move.to_refund and "out_refund" or "out_invoice"
inv_line = (
self.env["account.move.line"]
.sudo()
.search(
[
("sale_line_ids", "=", stock_move.sale_line_id.id),
("move_id.move_type", "=", inv_type),
]
)
)
if inv_line:
stock_move.invoice_line_ids = [(4, m.id) for m in inv_line]
return res
def get_moves_delivery_link_invoice(self):
return self.filtered(
lambda x: x.state == "done"
and not x.scrapped
and (
x.location_id.usage == "internal"
or (x.location_dest_id.usage == "internal" and x.to_refund)
)
)
| 38.476923 | 2,501 |
1,543 | py | PYTHON | 15.0 | # Copyright 2013-15 Agile Business Group sagl (<http://www.agilebg.com>)
# Copyright 2015-2016 AvanzOSC
# Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# Copyright 2017 Jacques-Etienne Baudoux <je@bcim.be>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import api, fields, models
class StockPicking(models.Model):
_inherit = "stock.picking"
invoice_ids = fields.Many2many(
comodel_name="account.move", copy=False, string="Invoices", readonly=True
)
invoice_count = fields.Integer(
string="Invoices Orders", compute="_compute_invoice_count"
)
def action_view_invoice(self):
"""This function returns an action that display existing invoices
of given stock pickings.
It can either be a in a list or in a form view, if there is only
one invoice to show.
"""
self.ensure_one()
form_view_name = "account.view_move_form"
result = self.env["ir.actions.act_window"]._for_xml_id(
"account.action_move_out_invoice_type"
)
if len(self.invoice_ids) > 1:
result["domain"] = "[('id', 'in', %s)]" % self.invoice_ids.ids
else:
form_view = self.env.ref(form_view_name)
result["views"] = [(form_view.id, "form")]
result["res_id"] = self.invoice_ids.id
return result
@api.depends("invoice_ids")
def _compute_invoice_count(self):
for order in self:
order.invoice_count = len(order.invoice_ids)
| 36.738095 | 1,543 |
1,334 | py | PYTHON | 15.0 | # Copyright 2022 Tecnativa - Carlos Roca
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import models
class AccountMoveReversal(models.TransientModel):
_inherit = "account.move.reversal"
def reverse_moves(self):
"""Link return moves to the lines of refund invoice"""
action = super(
AccountMoveReversal, self.with_context(force_copy_stock_moves=True)
).reverse_moves()
if "res_id" in action:
moves = self.env["account.move"].browse(action["res_id"])
else:
moves = self.env["account.move"].search(action["domain"])
if self.refund_method == "modify":
origin_moves = self.move_ids
for line in origin_moves.mapped("invoice_line_ids"):
reverse_moves = line.move_line_ids.mapped("returned_move_ids")
if reverse_moves:
moves.mapped("invoice_line_ids").filtered(
lambda m: m.product_id == line.product_id
).move_line_ids = reverse_moves
else:
for line in moves.mapped("invoice_line_ids"):
reverse_moves = line.move_line_ids.mapped("returned_move_ids")
if reverse_moves:
line.move_line_ids = reverse_moves
return action
| 43.032258 | 1,334 |
656 | py | PYTHON | 15.0 | # Copyright 2021 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Stock Move Change Source Location",
"summary": """
This module allows you to change the source location of a stock move from the
picking
""",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "ForgeFlow S.L.,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock"],
"data": [
"security/ir.model.access.csv",
"wizards/stock_move_change_source_location_wizard.xml",
"views/stock_picking_view.xml",
],
}
| 32.8 | 656 |
7,300 | py | PYTHON | 15.0 | # Copyright 2021 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase
class TestStockMoveChangeSourceLocation(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestStockMoveChangeSourceLocation, cls).setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.Location = cls.env["stock.location"]
cls.PickingType = cls.env["stock.picking.type"]
cls.Picking = cls.env["stock.picking"]
cls.Product = cls.env["product.template"]
cls.Wizard = cls.env["stock.move.change.source.location.wizard"]
cls.warehouse = cls.env["stock.warehouse"].create(
{
"name": "warehouse - test",
"code": "WH-TEST",
}
)
# cls.warehouse.lot_stock_id.id
cls.product = cls.Product.create(
{
"name": "Product - Test",
"type": "product",
"list_price": 100.00,
"standard_price": 100.00,
}
)
cls.product2 = cls.Product.create(
{
"name": "Product2 - Test",
"type": "product",
"list_price": 100.00,
"standard_price": 100.00,
}
)
cls.customer = cls.env["res.partner"].create({"name": "Customer - test"})
cls.picking_type = cls.PickingType.search(
[("warehouse_id", "=", cls.warehouse.id), ("code", "=", "outgoing")]
)
cls.picking = cls.Picking.create(
{
"name": "picking - test 01",
"location_id": cls.warehouse.lot_stock_id.id,
"location_dest_id": cls.warehouse.wh_output_stock_loc_id.id,
"picking_type_id": cls.picking_type.id,
"move_lines": [
(
0,
0,
{
"name": cls.product.name,
"product_id": cls.product.product_variant_ids.id,
"product_uom_qty": 20.0,
"product_uom": cls.product.uom_id.id,
"location_id": cls.warehouse.lot_stock_id.id,
"location_dest_id": cls.warehouse.wh_output_stock_loc_id.id,
},
),
(
0,
0,
{
"name": cls.product.name,
"product_id": cls.product2.product_variant_ids.id,
"product_uom_qty": 60.0,
"product_uom": cls.product.uom_id.id,
"location_id": cls.warehouse.lot_stock_id.id,
"location_dest_id": cls.warehouse.wh_output_stock_loc_id.id,
},
),
],
}
)
def qty_on_hand(self, product):
self.env["stock.quant"].with_context(inventory_mode=True).create(
{
"product_id": product.id,
"inventory_quantity": 200,
"location_id": self.warehouse.lot_stock_id.id,
}
).action_apply_inventory()
def test_stock_move_change_source_location_all(self):
self.qty_on_hand(self.product.product_variant_ids)
self.qty_on_hand(self.product2.product_variant_ids)
self.picking.action_assign()
new_location_id = self.Location.create(
{"name": "Shelf 1", "location_id": self.warehouse.lot_stock_id.id}
)
wiz = self.Wizard.with_context(
active_model=self.picking._name,
active_ids=self.picking.ids,
).create({"new_location_id": new_location_id.id, "moves_to_change": "all"})
move_lines = self.picking.mapped("move_lines")
self.assertEqual(
wiz.warehouse_view_location_id,
self.picking.location_id.warehouse_id.view_location_id,
)
self.assertEqual(wiz.old_location_id, move_lines[:1].location_id)
wiz.action_apply()
move_lines = self.picking.mapped("move_lines.location_id")
self.assertEqual(len(move_lines), 1)
def test_stock_move_change_source_location_matched(self):
self.qty_on_hand(self.product.product_variant_ids)
self.qty_on_hand(self.product2.product_variant_ids)
self.picking.action_assign()
new_location_id = self.Location.create(
{"name": "Shelf 1", "location_id": self.warehouse.lot_stock_id.id}
)
other_location_id = self.Location.create(
{"name": "Shelf 2", "location_id": self.warehouse.lot_stock_id.id}
)
self.picking.action_assign()
move_lines = self.picking.mapped("move_lines")
move_lines[:1].write({"location_id": other_location_id.id})
wiz = self.Wizard.with_context(
active_model=self.picking._name,
active_ids=self.picking.ids,
).create(
{
"old_location_id": self.picking.location_id.id,
"new_location_id": new_location_id.id,
"moves_to_change": "matched",
}
)
wiz.action_apply()
move_lines = self.picking.mapped("move_lines.location_id")
self.assertEqual(len(move_lines), 2)
def test_stock_move_change_source_location_manual(self):
self.qty_on_hand(self.product.product_variant_ids)
self.qty_on_hand(self.product2.product_variant_ids)
self.picking.action_assign()
new_location_id = self.Location.create(
{"name": "Shelf 1", "location_id": self.warehouse.lot_stock_id.id}
)
wiz = self.Wizard.with_context(
active_model=self.picking._name,
active_ids=self.picking.ids,
).create(
{
"new_location_id": new_location_id.id,
"moves_to_change": "manual",
"move_lines": [(6, 0, self.picking.move_lines[0].ids)],
}
)
move_lines = self.picking.mapped("move_lines")
self.assertEqual(wiz.old_location_id, move_lines[:1].location_id)
wiz.action_apply()
move_lines = self.picking.mapped("move_lines.location_id")
self.assertEqual(len(move_lines), 2)
def test_stock_move_change_source_location_failed(self):
self.qty_on_hand(self.product.product_variant_ids)
self.qty_on_hand(self.product2.product_variant_ids)
self.picking.action_assign()
for move in self.picking.move_lines:
move.quantity_done = 1
self.picking._action_done()
new_location_id = self.Location.create(
{"name": "Shelf 1", "location_id": self.warehouse.lot_stock_id.id}
)
wiz = self.Wizard.with_context(
active_model=self.picking._name,
active_ids=self.picking.ids,
).create({"new_location_id": new_location_id.id, "moves_to_change": "all"})
with self.assertRaises(UserError):
wiz.action_apply()
| 41.242938 | 7,300 |
5,288 | py | PYTHON | 15.0 | # Copyright 2021 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class StockMoveChangeSourceLocation(models.TransientModel):
_name = "stock.move.change.source.location.wizard"
_description = "Stock Move Change Source Location Wizard"
def _default_old_location_id(self):
stock_picking_obj = self.env["stock.picking"]
pickings = stock_picking_obj.browse(self.env.context["active_ids"])
first_move_line = pickings.mapped("move_lines")[:1]
return first_move_line.location_id.id
def _get_allowed_old_location_domain(self):
stock_picking_obj = self.env["stock.picking"]
pickings = stock_picking_obj.browse(self.env.context.get("active_ids", []))
return [("id", "in", pickings.mapped("move_lines.location_id").ids)]
def _get_allowed_new_location_domain(self):
stock_picking_obj = self.env["stock.picking"]
picking = stock_picking_obj.browse(self.env.context.get("active_ids", []))
warehouse = picking.location_id.warehouse_id
return [
("id", "child_of", warehouse.view_location_id.id),
("usage", "=", "internal"),
]
warehouse_view_location_id = fields.Many2one(
comodel_name="stock.location",
string="Warehouse View Location",
required=True,
readonly=True,
)
old_location_id = fields.Many2one(
comodel_name="stock.location",
string="Old location",
default=_default_old_location_id,
domain=lambda self: self._get_allowed_old_location_domain(),
)
new_location_id = fields.Many2one(
comodel_name="stock.location",
string="New location",
required=True,
domain=_get_allowed_new_location_domain,
)
moves_to_change = fields.Selection(
selection=[
("all", "Change All moves"),
("matched", "Change only moves with matched OLD location"),
("manual", "Select moves to change"),
],
string="Operations to change",
required=True,
default="all",
help="Select which kind of selection of the moves you want to do",
)
move_lines = fields.Many2many("stock.move", string="Move lines")
def _prepare_default_values(self, picking):
warehouse = picking.location_id.warehouse_id
return {"warehouse_view_location_id": warehouse.view_location_id.id}
@api.model
def default_get(self, fields_list):
res = super().default_get(fields_list)
active_model = self.env.context["active_model"]
active_ids = self.env.context["active_ids"] or []
picking = self.env[active_model].browse(active_ids)
res.update(self._prepare_default_values(picking))
return res
def _get_allowed_states(self):
return ["waiting", "partially_available", "confirmed", "assigned"]
def _check_allowed_pickings(self, pickings):
forbidden_pickings = pickings.filtered(
lambda x: x.state not in self._get_allowed_states()
)
if forbidden_pickings:
raise UserError(
_(
"You can not change move source location if "
"picking state is not in %s"
)
% ", ".join(self._get_allowed_states())
)
def _check_allowed_moves(self, moves):
forbidden_moves = moves.filtered(
lambda x: x.state not in self._get_allowed_states()
)
if forbidden_moves:
raise UserError(
_(
"You can not change move source location if "
"the move state is not in %s"
)
% ", ".join(self._get_allowed_states())
)
if any([move.move_orig_ids for move in moves]):
raise UserError(
_(
"You cannot change source location if any of the moves "
"has an origin move."
)
)
def action_apply(self):
stock_picking_obj = self.env["stock.picking"]
pickings = stock_picking_obj.browse(self.env.context["active_ids"])
self._check_allowed_pickings(pickings)
move_lines = pickings.mapped("move_lines")
vals = {"location_id": self.new_location_id.id}
if self.moves_to_change == "all":
moves_to_change = move_lines
elif self.moves_to_change == "matched":
# Only write operations destination location if the location is
# the same that old location value
moves_to_change = move_lines.filtered(
lambda x: x.location_id == self.old_location_id
)
else:
# Only write operations destination location on the selected moves
moves_to_change = self.move_lines
self._check_allowed_moves(moves_to_change)
# Unreserve moves first
moves_to_change._do_unreserve()
# Change source location
moves_to_change.write(vals)
# Check availability afterward
moves_to_change._action_assign()
return {"type": "ir.actions.act_window_close"}
| 38.043165 | 5,288 |
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,819 | 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-workflow",
description="Meta package for oca-stock-logistics-workflow Odoo addons",
version=version,
install_requires=[
'odoo-addon-delivery_procurement_group_carrier>=15.0dev,<15.1dev',
'odoo-addon-purchase_stock_picking_invoice_link>=15.0dev,<15.1dev',
'odoo-addon-sale_line_returned_qty>=15.0dev,<15.1dev',
'odoo-addon-sale_line_returned_qty_mrp>=15.0dev,<15.1dev',
'odoo-addon-sale_order_global_stock_route>=15.0dev,<15.1dev',
'odoo-addon-stock_delivery_note>=15.0dev,<15.1dev',
'odoo-addon-stock_landed_costs_delivery>=15.0dev,<15.1dev',
'odoo-addon-stock_landed_costs_purchase_auto>=15.0dev,<15.1dev',
'odoo-addon-stock_landed_costs_security>=15.0dev,<15.1dev',
'odoo-addon-stock_lot_on_hand_first>=15.0dev,<15.1dev',
'odoo-addon-stock_lot_product_qty_search>=15.0dev,<15.1dev',
'odoo-addon-stock_move_change_source_location>=15.0dev,<15.1dev',
'odoo-addon-stock_move_consu_location_from_putaway>=15.0dev,<15.1dev',
'odoo-addon-stock_move_line_auto_fill>=15.0dev,<15.1dev',
'odoo-addon-stock_move_quick_lot>=15.0dev,<15.1dev',
'odoo-addon-stock_no_negative>=15.0dev,<15.1dev',
'odoo-addon-stock_owner_restriction>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_assign_serial_final>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_auto_create_lot>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_back2draft>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_backorder_strategy>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_batch_extended>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_batch_extended_account>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_batch_extended_account_sale_type>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_filter_lot>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_info_lot>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_invoice_link>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_line_sequence>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_mass_action>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_operation_quick_change>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_product_assortment>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_product_assortment_availability_inline>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_product_availability_inline>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_product_availability_search>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_purchase_order_link>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_return_restricted_qty>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_sale_order_link>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_send_by_mail>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_show_backorder>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_show_return>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_warn_message>=15.0dev,<15.1dev',
'odoo-addon-stock_picking_whole_scrap>=15.0dev,<15.1dev',
'odoo-addon-stock_production_lot_active>=15.0dev,<15.1dev',
'odoo-addon-stock_production_lot_traceability>=15.0dev,<15.1dev',
'odoo-addon-stock_push_delay>=15.0dev,<15.1dev',
'odoo-addon-stock_putaway_hook>=15.0dev,<15.1dev',
'odoo-addon-stock_restrict_lot>=15.0dev,<15.1dev',
'odoo-addon-stock_return_request>=15.0dev,<15.1dev',
'odoo-addon-stock_split_picking>=15.0dev,<15.1dev',
],
classifiers=[
'Programming Language :: Python',
'Framework :: Odoo',
'Framework :: Odoo :: 15.0',
]
)
| 57.863636 | 3,819 |
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 |
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 |
490 | py | PYTHON | 15.0 | # Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Stock Picking Warn Message",
"summary": """
Add a popup warning on picking to ensure warning is populated""",
"version": "15.0.1.0.1",
"license": "AGPL-3",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock"],
"data": ["views/stock_picking_views.xml"],
}
| 35 | 490 |
6,010 | py | PYTHON | 15.0 | # Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestStockPickingWarnMessage(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# disable tracking test suite wise
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.user_model = cls.env["res.users"].with_context(no_reset_password=True)
cls.warehouse = cls.env.ref("stock.warehouse0")
cls.picking_type_out = cls.warehouse.out_type_id
cls.customer_location = cls.env.ref("stock.stock_location_customers")
cls.product = cls.env.ref("product.product_product_4")
cls.warn_msg_parent = "This customer has a warn from parent"
cls.parent = cls.env["res.partner"].create(
{
"name": "Customer with a warn",
"email": "customer@warn.com",
"picking_warn": "warning",
"picking_warn_msg": cls.warn_msg_parent,
}
)
cls.warn_msg = "This customer has a warn"
cls.partner = cls.env["res.partner"].create(
{
"name": "Customer with a warn",
"email": "customer@warn.com",
"picking_warn": "warning",
"picking_warn_msg": cls.warn_msg,
}
)
def test_compute_picking_warn_msg(self):
picking = self.env["stock.picking"].create(
{
"partner_id": self.partner.id,
"picking_type_id": self.picking_type_out.id,
"location_id": self.picking_type_out.default_location_src_id.id,
"location_dest_id": self.customer_location.id,
"move_lines": [
(
0,
0,
{
"name": self.product.name,
"product_id": self.product.id,
"product_uom": self.product.uom_id.id,
"product_uom_qty": 1,
"location_id": self.picking_type_out.default_location_src_id.id,
"location_dest_id": self.customer_location.id,
},
),
],
}
)
self.assertEqual(picking.picking_warn_msg, self.warn_msg)
def test_compute_picking_warn_msg_parent(self):
self.partner.update({"parent_id": self.parent.id})
picking = self.env["stock.picking"].create(
{
"partner_id": self.partner.id,
"picking_type_id": self.picking_type_out.id,
"location_id": self.picking_type_out.default_location_src_id.id,
"location_dest_id": self.customer_location.id,
"move_lines": [
(
0,
0,
{
"name": self.product.name,
"product_id": self.product.id,
"product_uom": self.product.uom_id.id,
"product_uom_qty": 1,
"location_id": self.picking_type_out.default_location_src_id.id,
"location_dest_id": self.customer_location.id,
},
),
],
}
)
self.assertEqual(
picking.picking_warn_msg, self.warn_msg_parent + "\n" + self.warn_msg
)
def test_compute_picking_warn(self):
picking = self.env["stock.picking"].create(
{
"partner_id": self.partner.id,
"picking_type_id": self.picking_type_out.id,
"location_id": self.picking_type_out.default_location_src_id.id,
"location_dest_id": self.customer_location.id,
"move_lines": [
(
0,
0,
{
"name": self.product.name,
"product_id": self.product.id,
"product_uom": self.product.uom_id.id,
"product_uom_qty": 1,
"location_id": self.picking_type_out.default_location_src_id.id,
"location_dest_id": self.customer_location.id,
},
),
],
}
)
self.partner.update({"picking_warn": "block"})
self.assertEqual(picking.picking_warn, "block")
self.partner.update({"picking_warn": "warning"})
self.assertEqual(picking.picking_warn, "warning")
# Check that block always overrules warning
self.partner.update({"parent_id": self.parent.id})
self.parent.update({"picking_warn": "warning"})
self.partner.update({"picking_warn": "block"})
self.assertEqual(picking.picking_warn, "block")
self.parent.update({"picking_warn": "block"})
self.partner.update({"picking_warn": "warning"})
self.assertEqual(picking.picking_warn, "block")
# We should still see the warning of the partner even when the parent partner
# has no warning set
self.parent.update({"picking_warn": "no-message"})
self.assertEqual(picking.picking_warn, "warning")
# When both the partner and the parent partner have no message set we expect
# to see that also in the picking
self.partner.update({"picking_warn": "no-message"})
self.assertEqual(picking.picking_warn, "no-message")
# On the other hand even when the partner has no warning set we still see
# the one from the parent
self.parent.update({"picking_warn": "warning"})
self.assertEqual(picking.picking_warn, "warning")
| 42.928571 | 6,010 |
1,850 | py | PYTHON | 15.0 | # Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class StockPicking(models.Model):
_inherit = "stock.picking"
picking_warn = fields.Text(compute="_compute_picking_warn")
picking_warn_msg = fields.Text(compute="_compute_picking_warn_msg")
@api.depends(
"state",
"partner_id.picking_warn",
"partner_id.commercial_partner_id.picking_warn",
)
def _compute_picking_warn(self):
for rec in self:
picking_warn = "no-message"
if rec.state not in ["done", "cancel"] and rec.partner_id:
p = rec.partner_id.commercial_partner_id
if p.picking_warn == "block" or rec.partner_id.picking_warn == "block":
picking_warn = "block"
elif (
p.picking_warn == "warning"
or rec.partner_id.picking_warn == "warning"
):
picking_warn = "warning"
rec.picking_warn = picking_warn
@api.depends(
"state",
"partner_id.picking_warn",
"partner_id.commercial_partner_id.picking_warn",
)
def _compute_picking_warn_msg(self):
for rec in self:
picking_warn_msg = ""
if rec.state not in ["done", "cancel"] and rec.partner_id:
p = rec.partner_id.commercial_partner_id
separator = ""
if p.picking_warn != "no-message":
separator = "\n"
picking_warn_msg += p.picking_warn_msg
if p != rec.partner_id and rec.partner_id.picking_warn != "no-message":
picking_warn_msg += separator + rec.partner_id.picking_warn_msg
rec.picking_warn_msg = picking_warn_msg or False
| 37.755102 | 1,850 |
625 | py | PYTHON | 15.0 | # Copyright 2021 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock picking filter lot",
"summary": "In picking out lots' selection, filter lots based on their location",
"version": "15.0.1.0.1",
"category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Agile Business Group, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["stock"],
"data": ["views/stock_move_line_view.xml", "views/stock_scrap_view.xml"],
}
| 41.666667 | 625 |
636 | py | PYTHON | 15.0 | # Copyright 2018 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class StockProductionLot(models.Model):
_inherit = "stock.production.lot"
location_ids = fields.Many2many(
comodel_name="stock.location", compute="_compute_location_ids", store=True
)
@api.depends("quant_ids", "quant_ids.location_id", "quant_ids.quantity")
def _compute_location_ids(self):
for lot in self:
lot.location_ids = lot.quant_ids.filtered(lambda l: l.quantity > 0).mapped(
"location_id"
)
| 33.473684 | 636 |
563 | py | PYTHON | 15.0 | # Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
"name": "Sale Line Returned Qty Mrp",
"summary": "Track returned quantity of sale order lines for BoM products.",
"version": "15.0.1.0.1",
"category": "Sales",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"license": "LGPL-3",
"installable": True,
"depends": ["sale_line_returned_qty", "mrp"],
"auto_install": True,
}
| 37.533333 | 563 |
7,291 | py | PYTHON | 15.0 | # Copyright 2022 ForgeFlow (http://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo.tests import Form, common
class TestSaleLineReturnedQtyMrp(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.warehouse = cls.env.ref("stock.warehouse0")
route_manufacture = cls.warehouse.manufacture_pull_id.route_id
route_mto = cls.warehouse.mto_pull_id.route_id
route_buy = cls.warehouse.buy_pull_id.route_id
dropshipping_route = cls.env["stock.location.route"].create(
{
"name": "Dropship",
"sale_selectable": True,
"product_selectable": True,
"product_categ_selectable": True,
}
)
# Create dropship product
cls.dropship_product_main = cls.env["product.product"].create(
{"name": "Large Desk"}
)
vendor1 = cls.env["res.partner"].create({"name": "vendor1"})
seller1 = cls.env["product.supplierinfo"].create(
{
"name": vendor1.id,
"price": 8,
}
)
seller2 = cls.env["product.supplierinfo"].create(
{
"name": vendor1.id,
"price": 8,
}
)
# Create Kit product
cls.product = cls.env["product.product"].create(
{
"name": "test kit",
"type": "product",
"route_ids": [(6, 0, [route_manufacture.id, route_mto.id])],
}
)
cls.c1 = cls.env["product.product"].create(
{"name": "test component 1", "type": "product"}
)
cls.c2 = cls.env["product.product"].create(
{"name": "test component 2", "type": "product"}
)
cls.c3 = cls.env["product.product"].create(
{
"name": "test component 3",
"type": "product",
"route_ids": [
(6, 0, [dropshipping_route.id, route_mto.id, route_buy.id])
],
"seller_ids": [(6, 0, [seller1.id])],
}
)
cls.c4 = cls.env["product.product"].create(
{
"name": "test component 4",
"type": "product",
"route_ids": [
(6, 0, [dropshipping_route.id, route_mto.id, route_buy.id])
],
"seller_ids": [(6, 0, [seller2.id])],
}
)
# Create BoM
cls.bom = cls.env["mrp.bom"].create(
{
"product_tmpl_id": cls.product.product_tmpl_id.id,
"product_id": cls.product.id,
"product_qty": 1,
"type": "phantom",
}
)
# Create bom lines
cls.env["mrp.bom.line"].create(
{"bom_id": cls.bom.id, "product_id": cls.c1.id, "product_qty": 1}
)
cls.env["mrp.bom.line"].create(
{"bom_id": cls.bom.id, "product_id": cls.c2.id, "product_qty": 1}
)
# Create dropshipping BoM
cls.dropship_bom = cls.env["mrp.bom"].create(
{
"product_tmpl_id": cls.dropship_product_main.product_tmpl_id.id,
"product_id": cls.dropship_product_main.id,
"product_qty": 1,
"type": "phantom",
}
)
# Create bom lines
cls.env["mrp.bom.line"].create(
{"bom_id": cls.dropship_bom.id, "product_id": cls.c3.id, "product_qty": 1}
)
cls.env["mrp.bom.line"].create(
{"bom_id": cls.dropship_bom.id, "product_id": cls.c4.id, "product_qty": 1}
)
# Add components stock
cls.env["stock.quant"].create(
{
"product_id": cls.c1.id,
"location_id": cls.warehouse.lot_stock_id.id,
"quantity": 100,
}
)
cls.env["stock.quant"].create(
{
"product_id": cls.c2.id,
"location_id": cls.warehouse.lot_stock_id.id,
"quantity": 100,
}
)
cls.partner = cls.env["res.partner"].create({"name": "test - partner"})
order_form = Form(cls.env["sale.order"])
order_form.partner_id = cls.partner
with order_form.order_line.new() as line_form:
line_form.product_id = cls.product
line_form.product_uom_qty = 10
line_form.price_unit = 1000
cls.order = order_form.save()
# create dropship order
dropship_order_form = Form(cls.env["sale.order"])
dropship_order_form.partner_id = cls.partner
with dropship_order_form.order_line.new() as line_form:
line_form.product_id = cls.dropship_product_main
line_form.product_uom_qty = 10
line_form.price_unit = 1000
cls.dropship_order = dropship_order_form.save()
def _return_picking(self, picking, qty, to_refund=True):
"""Helper method to create a return of the original picking. It could
be refundable or not"""
return_wiz_form = Form(
self.env["stock.return.picking"].with_context(
active_ids=picking.ids,
active_id=picking.ids[0],
active_model="stock.picking",
)
)
return_wiz = return_wiz_form.save()
return_wiz.product_return_moves.quantity = qty
return_wiz.product_return_moves.to_refund = to_refund
res = return_wiz.create_returns()
return_picking = self.env["stock.picking"].browse(res["res_id"])
self._validate_picking(return_picking)
def _validate_picking(self, picking):
"""Helper method to confirm the pickings"""
for line in picking.move_lines:
line.quantity_done = line.product_uom_qty
picking._action_done()
def test_01_returned_qty(self):
self.order.action_confirm()
so_line = self.order.order_line[0]
self.assertEqual(so_line.qty_returned, 0.0)
# Deliver the order
picking = self.order.picking_ids
self.assertEqual(len(picking.move_lines), 2)
picking.action_assign()
self._validate_picking(picking)
self.assertEqual(so_line.qty_returned, 0.0)
# Make a return for 5 of the 10 units delivered
self._return_picking(picking, 5.0, to_refund=True)
self.assertEqual(so_line.qty_returned, 5.0)
def test_02_returned_qty(self):
self.dropship_order.action_confirm()
po = self.env["purchase.order"].search(
[("group_id", "=", self.dropship_order.procurement_group_id.id)]
)
po.button_confirm()
so_line = self.dropship_order.order_line[0]
self.assertEqual(so_line.qty_returned, 0.0)
# Deliver the order
picking = self.dropship_order.picking_ids
self.assertEqual(len(picking.move_lines), 2)
picking.action_assign()
self._validate_picking(picking)
self.assertEqual(so_line.qty_returned, 0.0)
self._return_picking(picking, 5.0, to_refund=True)
self.assertEqual(so_line.qty_returned, 5.0)
| 37.777202 | 7,291 |
4,404 | py | PYTHON | 15.0 | # Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import api, models
from odoo.tools import float_compare
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
@api.depends(
"move_ids.state",
"move_ids.scrapped",
"move_ids.product_uom_qty",
"move_ids.product_uom",
)
def _compute_qty_returned(self):
# Based on the standard method in 'sale_mrp' to compute qty_delivered
res = super()._compute_qty_returned()
for order_line in self:
if order_line.qty_delivered_method == "stock_move":
boms = order_line.move_ids.filtered(
lambda m: m.state != "cancel"
).mapped("bom_line_id.bom_id")
dropship = any([m._is_dropshipped() for m in order_line.move_ids])
if not boms and dropship:
boms = boms._bom_find(
product=order_line.product_id,
company_id=order_line.company_id.id,
bom_type="phantom",
)
relevant_bom = boms.filtered(
lambda b: b.type == "phantom"
and (
b.product_id == order_line.product_id
or (
b.product_tmpl_id == order_line.product_id.product_tmpl_id
and not b.product_id
)
)
)
if relevant_bom:
if dropship:
moves = order_line.move_ids.filtered(
lambda m: m.state != "cancel"
)
if any(
(
m.location_dest_id.usage != "customer"
and m.state == "done"
and float_compare(
m.quantity_done,
sum(
sub_m.product_uom._compute_quantity(
sub_m.quantity_done, m.product_uom
)
for sub_m in m.returned_move_ids
if sub_m.state == "done"
),
precision_rounding=m.product_uom.rounding,
)
> 0
)
for m in moves
):
order_line.qty_returned = order_line.product_uom_qty
else:
order_line.qty_returned = 0.0
continue
moves = order_line.move_ids.filtered(
lambda m: m.state == "done" and not m.scrapped
)
filters = {
"incoming_moves": lambda m: m.location_dest_id.usage
!= "customer"
and m.to_refund,
"outgoing_moves": lambda m: False,
}
order_qty = order_line.product_uom._compute_quantity(
order_line.product_uom_qty, relevant_bom.product_uom_id
)
qty_returned = moves._compute_kit_quantities(
order_line.product_id, order_qty, relevant_bom, filters
)
order_line.qty_returned = (
relevant_bom.product_uom_id._compute_quantity(
qty_returned, order_line.product_uom
)
)
elif boms:
if all(
[
m.state == "done" and m.location_dest_id.usage == "customer"
for m in order_line.move_ids
]
):
order_line.qty_returned = 0.0
else:
order_line.qty_returned = order_line.product_uom_qty
return res
| 44.04 | 4,404 |
477 | py | PYTHON | 15.0 | {
"name": "Stock Transfers Lot Info",
"summary": "Add lot information on Stock Transfer lines",
"website": "https://github.com/OCA/stock-logistics-workflow",
"license": "AGPL-3",
"author": "S.P.O.C., Odoo Community Association (OCA)",
"category": "Warehouse",
"version": "15.0.1.0.0",
"application": False,
"installable": True,
"depends": ["stock"],
"data": ["views/product_template_views.xml", "views/stock_move_line_views.xml"],
}
| 36.692308 | 477 |
2,252 | py | PYTHON | 15.0 | from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase
class TestPickingValidation(TransactionCase):
def _create_picking(self, partner, p_type, src, dest):
picking = (
self.env["stock.picking"]
.with_context(default_immediate_transfer=True)
.create(
{
"partner_id": partner.id,
"picking_type_id": p_type.id,
"location_id": src.id,
"location_dest_id": dest.id,
}
)
)
return picking
def _create_move(self, product, src, dest, quantity=5.0, picking=None):
return self.env["stock.move"].create(
{
"name": "/",
"picking_id": picking.id if picking is not None else None,
"product_id": product.id,
"product_uom_qty": quantity,
"quantity_done": quantity,
"product_uom": product.uom_id.id,
"location_id": src.id,
"location_dest_id": dest.id,
}
)
def setUp(self):
super().setUp()
suppliers_location = self.env.ref("stock.stock_location_suppliers")
stock_location = self.env.ref("stock.stock_location_stock")
customers_location = self.env.ref("stock.stock_location_customers")
self.partner = self.env.ref("base.res_partner_2")
self.product = self.env.ref("product.product_product_25")
self.product.lot_info_usage = "required"
self.replenishment = self._create_move(
self.product, suppliers_location, stock_location, quantity=1
)
self.picking = self._create_picking(
self.partner,
self.env.ref("stock.picking_type_out"),
stock_location,
customers_location,
)
self.move = self._create_move(
self.product,
stock_location,
customers_location,
quantity=1,
picking=self.picking,
)
self.picking.action_confirm()
def test_picking_validation(self):
with self.assertRaises(UserError):
self.picking.button_validate()
| 34.121212 | 2,252 |
261 | py | PYTHON | 15.0 | from odoo import fields, models
class StockMoveLine(models.Model):
_inherit = "stock.move.line"
lot_info = fields.Char("Lot/Serial Number Info")
lot_info_usage = fields.Selection(
related="product_id.product_tmpl_id.lot_info_usage"
)
| 26.1 | 261 |
290 | py | PYTHON | 15.0 | from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
lot_info_usage = fields.Selection(
[("no", "No"), ("optional", "Optional"), ("required", "Required")],
default="no",
string="Lot Information Usage",
)
| 24.166667 | 290 |
874 | py | PYTHON | 15.0 | # Copyright 2022 Open Source Integrators (https://www.opensourceintegrators.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, exceptions, models
class StockPicking(models.Model):
_inherit = "stock.picking"
def _check_required_lot_info(self):
for picking in self:
lines_missing_lotinfo = picking.move_line_ids_without_package.filtered(
lambda x: x.lot_info_usage == "required" and not x.lot_info
)
if lines_missing_lotinfo:
raise exceptions.UserError(
_("Missing Lot Info for Products %s.")
% ", ".join(lines_missing_lotinfo.product_id.mapped("display_name"))
)
def button_validate(self):
res = super().button_validate()
self._check_required_lot_info()
return res
| 38 | 874 |
579 | py | PYTHON | 15.0 | # Copyright 2020 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Sale Order Global Stock Route",
"summary": "Add the possibility to choose one warehouse path for an order",
"version": "15.0.1.0.0",
"development_status": "Beta",
"category": "Warehouse",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["sale_stock"],
"data": ["views/sale_order_views.xml"],
}
| 36.1875 | 579 |
4,024 | py | PYTHON | 15.0 | # Copyright 2020 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
class SaleOrderGlobalStockRouteTest(TransactionCase):
@classmethod
def setUpClass(cls):
super(SaleOrderGlobalStockRouteTest, cls).setUpClass()
cls.partner = cls.env["res.partner"].create({"name": "Test"})
cls.product1 = cls.env["product.product"].create(
{"name": "test_product1", "type": "product"}
)
cls.product2 = cls.env["product.product"].create(
{"name": "test_product2", "type": "product"}
)
cls.route1 = cls.env["stock.location.route"].create(
{"name": "test_route_1", "sale_selectable": "True"}
)
cls.route2 = cls.env["stock.location.route"].create(
{"name": "test_route_2", "sale_selectable": "True"}
)
cls.order = cls.env["sale.order"].create(
[
{
"partner_id": cls.partner.id,
"order_line": [
(
0,
0,
{
"name": cls.product1.name,
"product_id": cls.product1.id,
"product_uom_qty": 1,
"product_uom": cls.product1.uom_id.id,
},
),
(
0,
0,
{
"name": cls.product2.name,
"product_id": cls.product2.id,
"product_uom_qty": 1,
"product_uom": cls.product2.uom_id.id,
},
),
],
},
]
)
def test_global_route(self):
self.order["route_id"] = self.route1.id
self.order._onchange_route_id()
for line in self.order.order_line:
self.assertTrue(line.route_id == self.route1)
def test_global_route02(self):
self.order["route_id"] = self.route1.id
for line in self.order.order_line:
line.product_id_change()
self.assertTrue(line.route_id == self.route1)
def test_routes_without_onchange(self):
new_order = self.env["sale.order"].create(
[
{
"partner_id": self.partner.id,
"order_line": [
(
0,
0,
{
"name": self.product1.name,
"product_id": self.product1.id,
"product_uom_qty": 1,
"product_uom": self.product1.uom_id.id,
},
),
(
0,
0,
{
"name": self.product2.name,
"product_id": self.product2.id,
"product_uom_qty": 1,
"product_uom": self.product2.uom_id.id,
},
),
],
"route_id": self.route1.id,
},
]
)
for line in new_order.order_line:
self.assertTrue(line.route_id == self.route1)
new_order.order_line[0].route_id = self.route2
new_order.write({})
self.assertTrue(new_order.order_line[0].route_id == self.route2)
new_order.write({"route_id": self.route2.id})
for line in new_order.order_line:
self.assertTrue(line.route_id == self.route2)
| 38.692308 | 4,024 |
1,765 | py | PYTHON | 15.0 | # Copyright 2020 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class SaleOrder(models.Model):
_inherit = "sale.order"
route_id = fields.Many2one(
comodel_name="stock.location.route",
string="Route",
domain=[("sale_selectable", "=", True)],
help="When you change this field all the lines will be changed."
" After use it you will be able to change each line.",
)
@api.onchange("route_id")
def _onchange_route_id(self):
"""We could do sale order line route_id field compute store writable.
But this field is created by Odoo so I prefer not modify it.
"""
self.order_line.route_id = self.route_id
def write(self, vals):
res = super().write(vals)
if "route_id" in vals:
lines = self.mapped("order_line").filtered(
lambda l: l.route_id.id != vals["route_id"]
)
lines.write({"route_id": vals["route_id"]})
return res
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
@api.onchange("product_id")
def product_id_change(self):
res = super().product_id_change()
if self.order_id.route_id:
self.route_id = self.order_id.route_id
return res
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if not vals.get("route_id", False):
order = self.env["sale.order"].browse(vals["order_id"])
if order.route_id:
vals["route_id"] = order.route_id.id
return super().create(vals_list)
| 34.607843 | 1,765 |
530 | py | PYTHON | 15.0 | # Copyright 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2017 Serpent Consulting Services Pvt. Ltd.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import SUPERUSER_ID
from odoo.api import Environment
def post_init_hook(cr, pool):
"""
Fetches all the pickings and resets the sequence of the move lines
"""
env = Environment(cr, SUPERUSER_ID, {})
stock = env["stock.picking"].search([])
stock.with_context(skip_update_line_ids=True)._reset_sequence()
| 35.333333 | 530 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.