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
|
|---|---|---|---|---|---|---|
264
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import models
class AccountMove(models.Model):
_inherit = "account.move"
def _validate_invoice(self):
return self.sudo().action_post()
| 24
| 264
|
593
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
invoicing_mode = fields.Selection([("standard", "Standard")], default="standard")
one_invoice_per_order = fields.Boolean(
default=False,
help="Do not group sale order into one invoice.",
)
@api.model
def _commercial_fields(self):
return super()._commercial_fields() + [
"invoicing_mode",
"one_invoice_per_order",
]
| 28.238095
| 593
|
884
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-2020 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Invoice Transmit Method",
"version": "15.0.1.1.0",
"category": "Accounting/Accounting",
"license": "AGPL-3",
"summary": "Configure invoice transmit method (email, post, portal, ...)",
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"website": "https://github.com/OCA/account-invoicing",
"depends": ["account", "base_view_inheritance_extension"],
"data": [
"security/ir.model.access.csv",
"views/account_move.xml",
"views/res_partner.xml",
"views/transmit_method.xml",
"data/transmit_method.xml",
],
"demo": ["demo/partner.xml"],
"installable": True,
}
| 36.833333
| 884
|
1,382
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-2020 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# Copyright 2021 Camptocamp SA (https://www.camptocamp.com).
# @author: Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestAccountInvoiceTransmitMethod(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.post_method = cls.env.ref("account_invoice_transmit_method.post")
cls.partner = cls.env["res.partner"].create(
{
"is_company": True,
"name": "Old School Company",
"customer_invoice_transmit_method_id": cls.post_method.id,
}
)
cls.sale_journal = cls.env["account.journal"].create(
{"code": "XYZZZ", "name": "sale journal (test)", "type": "sale"}
)
def test_create_invoice(self):
invoice = self.env["account.move"].create(
{
"move_type": "out_invoice",
"partner_id": self.partner.id,
"journal_id": self.sale_journal.id,
}
)
self.assertEqual(invoice.transmit_method_id, self.post_method)
| 39.457143
| 1,381
|
1,552
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-2020 Akretion France (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class AccountMove(models.Model):
_inherit = "account.move"
transmit_method_id = fields.Many2one(
"transmit.method",
string="Transmission Method",
compute="_compute_transmit_method_id",
store=True,
readonly=False,
tracking=True,
ondelete="restrict",
domain="""
[
'|',
('customer_ok', '=', invoice_filter_type_domain in (False, 'sale')),
('supplier_ok', '=', invoice_filter_type_domain in (False, 'purchase')),
]
""",
)
transmit_method_code = fields.Char(
string="Transmission Method Code",
related="transmit_method_id.code",
help="Technical field used for UX purposes",
)
@api.depends("partner_id", "move_type")
def _compute_transmit_method_id(self):
for rec in self:
if rec.partner_id and rec.is_sale_document():
rec.transmit_method_id = (
rec.partner_id.customer_invoice_transmit_method_id
)
elif rec.partner_id and rec.is_purchase_document():
rec.transmit_method_id = (
rec.partner_id.supplier_invoice_transmit_method_id
)
else:
rec.transmit_method_id = False
| 34.488889
| 1,552
|
920
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-2020 Akretion France (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class TransmitMethod(models.Model):
_name = "transmit.method"
_description = "Transmit Method of a document"
name = fields.Char(required=True, translate=True)
code = fields.Char(
copy=False,
help="Do not modify the code of an existing Transmit Method "
"because it may be used to identify a particular transmit method.",
)
active = fields.Boolean("active", default=True)
customer_ok = fields.Boolean(string="Selectable on Customers", default=True)
supplier_ok = fields.Boolean(string="Selectable on Vendors", default=True)
_sql_constraints = [
("code_unique", "unique(code)", "This transmit method code already exists!")
]
| 38.333333
| 920
|
1,408
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-2020 Akretion France (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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"
customer_invoice_transmit_method_id = fields.Many2one(
"transmit.method",
string="Customer Invoice Transmission Method",
company_dependent=True,
tracking=True,
ondelete="restrict",
domain=[("customer_ok", "=", True)],
)
customer_invoice_transmit_method_code = fields.Char(
related="customer_invoice_transmit_method_id.code",
string="Customer Invoice Transmission Method Code",
)
supplier_invoice_transmit_method_id = fields.Many2one(
"transmit.method",
string="Vendor Invoice Reception Method",
company_dependent=True,
tracking=True,
ondelete="restrict",
domain=[("supplier_ok", "=", True)],
)
supplier_invoice_transmit_method_code = fields.Char(
related="supplier_invoice_transmit_method_id.code",
string="Vendor Invoice Reception Method Code",
)
@api.model
def _commercial_fields(self):
return super()._commercial_fields() + [
"customer_invoice_transmit_method_id",
"supplier_invoice_transmit_method_id",
]
| 34.341463
| 1,408
|
583
|
py
|
PYTHON
|
15.0
|
# Copyright 2023 Moduon Team S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Receipts Print and Send",
"summary": "Send receipts",
"version": "15.0.1.0.1",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/account-invoicing",
"author": "Moduon, Odoo Community Association (OCA)",
"maintainers": ["Shide"],
"license": "LGPL-3",
"installable": True,
"depends": [
"account",
],
"data": [
"views/account_move_views.xml",
"data/mail_template_data.xml",
],
}
| 29.15
| 583
|
953
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged("post_install", "-at_install")
class TestAccountReceipt(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.in_receipt = cls.init_invoice(
"in_receipt", products=cls.product_a + cls.product_b
)
cls.in_receipt._post()
cls.out_receipt = cls.init_invoice(
"out_receipt", products=cls.product_a + cls.product_b
)
cls.out_receipt._post()
def test_receipt_mail_template(self):
self.assertEqual(
(self.in_receipt | self.out_receipt)._get_mail_template(),
"account_receipt_send.email_template_edi_receipt",
"Mail template chosen wrong",
)
| 35.296296
| 953
|
319
|
py
|
PYTHON
|
15.0
|
from odoo import models
class AccountMove(models.Model):
_inherit = "account.move"
def _get_mail_template(self):
if all(move.move_type in {"out_receipt", "in_receipt"} for move in self):
return "account_receipt_send.email_template_edi_receipt"
return super()._get_mail_template()
| 31.9
| 319
|
604
|
py
|
PYTHON
|
15.0
|
# Copyright 2022 ForgeFlow, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Account Move Tier Validation - Forward Option",
"version": "15.0.1.0.0",
"category": "Accounting",
"website": "https://github.com/OCA/account-invoicing",
"author": "ForgeFlow,Odoo Community Association (OCA)",
"license": "AGPL-3",
"development_status": "Alpha",
"application": False,
"installable": True,
"auto_install": True,
"depends": ["base_tier_validation_forward", "account_move_tier_validation"],
"data": ["views/account_move_view.xml"],
}
| 37.75
| 604
|
595
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 QubiQ (http://www.qubiq.es)
# Copyright 2017 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Invoice Triple Discount",
"version": "15.0.1.0.1",
"category": "Accounting & Finance",
"author": "QubiQ, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
"license": "AGPL-3",
"summary": "Manage triple discount on invoice lines",
"depends": ["account"],
"data": ["report/invoice.xml", "views/account_move.xml"],
"installable": True,
}
| 39.666667
| 595
|
5,894
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import TransactionCase
from odoo.tests.common import Form
class TestInvoiceTripleDiscount(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestInvoiceTripleDiscount, cls).setUpClass()
cls.Account = cls.env["account.account"]
cls.AccountMove = cls.env["account.move"]
cls.AccountTax = cls.env["account.tax"]
cls.AccountType = cls.env["account.account.type"]
cls.Partner = cls.env["res.partner"]
cls.Journal = cls.env["account.journal"]
cls.partner = cls.Partner.create({"name": "test"})
cls.tax = cls.AccountTax.create(
{
"name": "TAX 15%",
"amount_type": "percent",
"type_tax_use": "purchase",
"amount": 15.0,
"country_id": cls.env.ref("base.us").id,
}
)
cls.account_type = cls.AccountType.create(
{"name": "Test", "type": "receivable", "internal_group": "income"}
)
cls.account = cls.Account.create(
{
"name": "Test account",
"code": "TEST",
"user_type_id": cls.account_type.id,
"reconcile": True,
}
)
cls.sale_journal = cls.Journal.search([("type", "=", "sale")], limit=1)
def create_simple_invoice(self, amount):
invoice_form = Form(
self.AccountMove.with_context(
default_move_type="out_invoice",
default_journal_id=self.sale_journal.id,
)
)
invoice_form.partner_id = self.partner
with invoice_form.invoice_line_ids.new() as line_form:
line_form.name = "Line 1"
line_form.quantity = 1
line_form.price_unit = amount
line_form.tax_ids.clear()
line_form.tax_ids.add(self.tax)
invoice = invoice_form.save()
return invoice
def test_01_discounts(self):
"""Tests multiple discounts in line with taxes"""
invoice = self.create_simple_invoice(200)
invoice_form = Form(invoice)
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.discount = 50.0
invoice_form.save()
invoice_line = invoice.invoice_line_ids[0]
# Adds a first discount
self.assertEqual(invoice.amount_total, 115.0)
# Adds a second discount over the price calculated before
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.discount2 = 40.0
invoice_form.save()
self.assertEqual(invoice.amount_total, 69.0)
# Adds a third discount over the price calculated before
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.discount3 = 50.0
invoice_form.save()
self.assertEqual(invoice.amount_total, 34.5)
# Deletes first discount
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.discount = 0
invoice_form.save()
self.assertEqual(invoice.amount_total, 69)
# Charge 5% over price:
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.discount = -5
invoice_form.save()
self.assertEqual(invoice.amount_total, 72.45)
self.assertEqual(invoice_line.price_unit, 200)
def test_02_discounts_multiple_lines(self):
invoice = self.create_simple_invoice(200)
invoice_form = Form(invoice)
with invoice_form.invoice_line_ids.new() as line_form:
line_form.name = "Line 2"
line_form.quantity = 1
line_form.price_unit = 500
line_form.tax_ids.clear()
invoice_form.save()
invoice_line2 = invoice.invoice_line_ids[1]
self.assertEqual(invoice_line2.price_subtotal, 500.0)
with invoice_form.invoice_line_ids.edit(1) as line_form:
line_form.discount3 = 50.0
invoice_form.save()
self.assertEqual(invoice.amount_total, 480.0)
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.discount = 50.0
invoice_form.save()
self.assertEqual(invoice.amount_total, 365.0)
def test_03_discounts_decimals_price(self):
"""
Tests discount with decimals price
causing a round up after discount
"""
invoice = self.create_simple_invoice(0)
invoice_form = Form(invoice)
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.name = "Line Decimals"
line_form.quantity = 9950
line_form.price_unit = 0.14
line_form.tax_ids.clear()
invoice_form.save()
invoice_line1 = invoice.invoice_line_ids[0]
self.assertEqual(invoice_line1.price_subtotal, 1393.0)
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.discount = 15.0
invoice_form.save()
self.assertEqual(invoice_line1.price_subtotal, 1184.05)
def test_04_discounts_decimals_tax(self):
"""
Tests amount tax with discount
"""
invoice = self.create_simple_invoice(0)
invoice_form = Form(invoice)
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.name = "Line Decimals"
line_form.quantity = 9950
line_form.price_unit = 0.14
line_form.discount = 0
line_form.discount2 = 0
invoice_form.save()
self.assertEqual(invoice.amount_tax, 208.95)
with invoice_form.invoice_line_ids.edit(0) as line_form:
line_form.discount = 15.0
invoice_form.save()
self.assertEqual(invoice.amount_tax, 177.61)
| 35.293413
| 5,894
|
1,890
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Tecnativa - David Vidal
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class AccountMove(models.Model):
_inherit = "account.move"
def _recompute_tax_lines(self, **kwargs):
"""
As the taxes are recalculated based on a single discount, we need to
simulate a multiple discount by changing the unit price. Values are
restored after the original process is done
"""
old_values_by_line_id = {}
# To simulate multiple discounts by changing the unit price, we need
# to increase the precision of the field otherwise the result is
# inaccurate, misaligning the taxes, we restore the value at the end
# of the process
digits = self.line_ids._fields["price_unit"]._digits
self.line_ids._fields["price_unit"]._digits = (16, 16)
for line in self.line_ids:
aggregated_discount = line._compute_aggregated_discount(line.discount)
old_values_by_line_id[line.id] = {
"price_unit": line.price_unit,
"discount": line.discount,
}
price_unit = line.price_unit * (1 - aggregated_discount / 100)
line.update({"price_unit": price_unit, "discount": 0})
self.line_ids._fields["price_unit"]._digits = digits
res = super(AccountMove, self)._recompute_tax_lines(**kwargs)
for line in self.line_ids:
if line.id not in old_values_by_line_id:
continue
line.update(old_values_by_line_id[line.id])
return res
def _has_discount(self):
self.ensure_one()
return any(
[
line._compute_aggregated_discount(line.discount) > 0
for line in self.invoice_line_ids
]
)
| 39.375
| 1,890
|
4,038
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import functools
from odoo import api, fields, models
from odoo.tools import float_compare
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
discount2 = fields.Float(
string="Discount 2 (%)",
digits="Discount",
)
discount3 = fields.Float(
string="Discount 3 (%)",
digits="Discount",
)
@api.model_create_multi
def create(self, values_list):
"""
During the create of move lines, if the system detect that there is a
difference between the balance and the price subtotal, it will update
the unit price. When computing those, Odoo base module use a single
discount on creation. So as there is a difference of the price given
by the UI and the price computed during create method, the system will
change the unit price of the invoice line. To avoid that, we update
the discount field to have the aggregated discount, and we change it
back after the creation.
(Similar to _recompute_tax_lines on account.move)
"""
old_values = []
dp_discount = self.env["decimal.precision"].precision_get("Discount")
for values in values_list:
old_discount = values.get("discount", 0.0)
new_discount = self._get_aggregated_discount_from_values(values)
tmp_values = {}
discount_changed = (
float_compare(old_discount, new_discount, precision_digits=dp_discount)
!= 0
)
if discount_changed:
values["discount"] = new_discount
tmp_values["discount"] = old_discount
old_values.append(tmp_values)
records = super(AccountMoveLine, self).create(values_list)
for index, record in enumerate(records):
values = old_values[index]
if values:
record.write(old_values[index])
return records
@api.onchange(
"discount",
"price_unit",
"tax_ids",
"quantity",
"discount2",
"discount3",
)
def _onchange_price_subtotal(self):
return super(AccountMoveLine, self)._onchange_price_subtotal()
def _get_price_total_and_subtotal(self, **kwargs):
self.ensure_one()
kwargs["discount"] = self._compute_aggregated_discount(
kwargs.get("discount") or self.discount
)
return super(AccountMoveLine, self)._get_price_total_and_subtotal(**kwargs)
def _get_fields_onchange_balance(self, **kwargs):
self.ensure_one()
kwargs["discount"] = self._compute_aggregated_discount(
kwargs.get("discount") or self.discount
)
return super(AccountMoveLine, self)._get_fields_onchange_balance(**kwargs)
def _compute_aggregated_discount(self, base_discount):
self.ensure_one()
discounts = [base_discount]
for discount_fname in self._get_multiple_discount_field_names():
discounts.append(getattr(self, discount_fname, 0.0))
return self._get_aggregated_multiple_discounts(discounts)
def _get_aggregated_discount_from_values(self, values):
discount_fnames = ["discount"]
discount_fnames.extend(self._get_multiple_discount_field_names())
discounts = []
for discount_fname in discount_fnames:
discounts.append(values.get(discount_fname) or 0.0)
return self._get_aggregated_multiple_discounts(discounts)
def _get_aggregated_multiple_discounts(self, discounts):
discount_values = []
for discount in discounts:
discount_values.append(1 - (discount or 0.0) / 100.0)
aggregated_discount = (
1 - functools.reduce((lambda x, y: x * y), discount_values)
) * 100
return aggregated_discount
def _get_multiple_discount_field_names(self):
return ["discount2", "discount3"]
| 37.738318
| 4,038
|
535
|
py
|
PYTHON
|
15.0
|
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Sales order invoicing by percentage of the quantity",
"version": "15.0.1.0.0",
"category": "Sales Management",
"license": "AGPL-3",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
"depends": ["sale"],
"data": ["wizards/sale_advance_payment_inv_views.xml"],
"installable": True,
"maintainers": ["pedrobaeza"],
}
| 35.666667
| 535
|
1,539
|
py
|
PYTHON
|
15.0
|
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import Form, TransactionCase
class TestSaleOrderInvoicingQtyPercentage(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.partner = cls.env["res.partner"].create({"name": "Test partner"})
cls.product = cls.env["product.product"].create(
{
"name": "Test product",
"detailed_type": "service",
"invoice_policy": "order",
}
)
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 = 20
cls.order = order_form.save()
cls.order.action_confirm()
cls.wizard = (
cls.env["sale.advance.payment.inv"]
.with_context(
active_id=cls.order.id,
active_ids=cls.order.ids,
active_model="sale.order",
)
.create({"advance_payment_method": "qty_percentage", "qty_percentage": 0.5})
)
def test_invoicing_same_data(self):
self.wizard.create_invoices()
self.assertEqual(self.order.invoice_ids.invoice_line_ids.quantity, 10)
self.assertEqual(self.order.order_line.qty_to_invoice, 10)
| 38.475
| 1,539
|
525
|
py
|
PYTHON
|
15.0
|
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class SaleOrder(models.Model):
_inherit = "sale.order.line"
def _prepare_invoice_line(self, **optional_values):
"""If invoicing by quantity percentage, modify quantities."""
res = super()._prepare_invoice_line(**optional_values)
if self.env.context.get("qty_percentage"):
res["quantity"] *= self.env.context["qty_percentage"]
return res
| 35
| 525
|
922
|
py
|
PYTHON
|
15.0
|
from odoo import fields, models
class SaleAdvancePaymentInv(models.TransientModel):
_inherit = "sale.advance.payment.inv"
advance_payment_method = fields.Selection(
# Added before "Down payment (percentage)" option
selection_add=[
("qty_percentage", "Percentage of the quantity"),
("percentage",),
],
ondelete={"qty_percentage": "set default"},
)
qty_percentage = fields.Float(string="Quantity percentage")
def create_invoices(self):
"""Inject context key for later use that information to modify quantities
and switch the invoiced method back to regular one for using the normal flow.
"""
if self.advance_payment_method == "qty_percentage":
self = self.with_context(qty_percentage=self.qty_percentage)
self.advance_payment_method = "delivered"
return super().create_invoices()
| 38.416667
| 922
|
639
|
py
|
PYTHON
|
15.0
|
# Copyright 2022 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Sale Invoicing Date Selection",
"summary": "Set date invoice when you create invoices",
"version": "15.0.1.0.0",
"development_status": "Beta",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/account-invoicing",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["sale"],
"data": ["wizard/sale_make_invoice_advance_views.xml"],
"maintainers": ["sergio-teruel"],
}
| 37.588235
| 639
|
1,864
|
py
|
PYTHON
|
15.0
|
# Copyright 2022 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo.tests import Form, TransactionCase
class TestSaleInvoicingDateSelection(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner = cls.env["res.partner"].create({"name": "partner - test"})
cls.partner_1 = cls.env["res.partner"].create({"name": "partner1 - test"})
cls.product = cls.env["product.product"].create(
{"name": "test invoicing", "type": "service", "invoice_policy": "order"}
)
def _create_sale_order(self, partner):
with Form(self.env["sale.order"]) as sale_form:
sale_form.partner_id = partner
with sale_form.order_line.new() as so_line_form:
so_line_form.product_id = self.product
so_line_form.price_unit = 100.00
return sale_form.save()
def test_andvance_invoice(self):
self.sale_order_1 = self._create_sale_order(self.partner)
self.sale_order_2 = self._create_sale_order(self.partner_1)
self.sale_order_1.action_confirm()
self.sale_order_2.action_confirm()
orders = self.sale_order_1 + self.sale_order_2
with Form(
self.env["sale.advance.payment.inv"].with_context(
active_model="sale.order", active_ids=orders.ids, open_invoices=True
)
) as wiz_invoice_form:
wiz_invoice_form.invoice_date = "2022-11-01"
wiz = wiz_invoice_form.save()
action = wiz.create_invoices()
invoices = self.env["account.move"].search(action["domain"])
self.assertEqual(fields.Date.to_string(invoices[0].invoice_date), "2022-11-01")
self.assertEqual(fields.Date.to_string(invoices[1].invoice_date), "2022-11-01")
| 45.463415
| 1,864
|
750
|
py
|
PYTHON
|
15.0
|
# Copyright 2022 Sergio Teruel <sergio.teruel@tecnativa.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class SaleAdvancePaymentInv(models.TransientModel):
_inherit = "sale.advance.payment.inv"
invoice_date = fields.Date()
def create_invoices(self):
"""
Add date to crate all invoices into user context
"""
ctx = self.env.context.copy()
if self.invoice_date:
ctx.update(
{
"default_invoice_date": self.invoice_date,
"default_date": self.invoice_date,
}
)
return super(SaleAdvancePaymentInv, self.with_context(**ctx)).create_invoices()
| 31.25
| 750
|
505
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account - Pricelist on Invoices",
"version": "15.0.1.0.2",
"summary": "Add partner pricelist on invoices",
"category": "Accounting & Finance",
"author": "GRAP," "Therp BV," "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
"license": "AGPL-3",
"depends": ["account"],
"data": ["views/account_invoice_view.xml"],
"installable": True,
}
| 36.071429
| 505
|
13,431
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import hashlib
import inspect
from odoo.exceptions import UserError
from odoo.tests import common
from odoo.addons.sale.models.sale_order_line import SaleOrderLine as upstream
# if this hash fails then the original function it was copied from
# needs to be checked to see if there are any major changes that
# need to be updated in this module's _get_real_price_currency
VALID_HASHES = ["ae1579f90ae87798e0d86f6b7427d4aa"]
class TestAccountMovePricelist(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.AccountMove = cls.env["account.move"]
cls.ProductPricelist = cls.env["product.pricelist"]
cls.FiscalPosition = cls.env["account.fiscal.position"]
cls.fiscal_position = cls.FiscalPosition.create(
{"name": "Test Fiscal Position", "active": True}
)
cls.journal_sale = cls.env["account.journal"].create(
{"name": "Test sale journal", "type": "sale", "code": "TEST_SJ"}
)
# Make sure the currency of the company is USD, as this not always happens
# To be removed in V17: https://github.com/odoo/odoo/pull/107113
cls.company = cls.env.company
cls.env.cr.execute(
"UPDATE res_company SET currency_id = %s WHERE id = %s",
(cls.env.ref("base.USD").id, cls.company.id),
)
cls.at_receivable = cls.env["account.account.type"].create(
{
"name": "Test receivable account",
"type": "receivable",
"internal_group": "income",
}
)
cls.a_receivable = cls.env["account.account"].create(
{
"name": "Test receivable account",
"code": "TEST_RA",
"user_type_id": cls.at_receivable.id,
"reconcile": True,
}
)
cls.product = cls.env["product.template"].create(
{"name": "Product Test", "list_price": 100.00}
)
cls.sale_pricelist = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist",
"item_ids": [
(
0,
0,
{
"applied_on": "1_product",
"compute_price": "fixed",
"fixed_price": 60.00,
"product_tmpl_id": cls.product.id,
},
)
],
}
)
cls.partner = cls.env["res.partner"].create(
{
"name": "Test Partner",
"property_product_pricelist": cls.sale_pricelist.id,
"property_account_receivable_id": cls.a_receivable.id,
"property_account_position_id": cls.fiscal_position.id,
}
)
cls.sale_pricelist_fixed_without_discount = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist",
"discount_policy": "without_discount",
"item_ids": [
(
0,
0,
{
"applied_on": "1_product",
"compute_price": "fixed",
"fixed_price": 60.00,
"product_tmpl_id": cls.product.id,
},
)
],
}
)
cls.sale_pricelist_with_discount = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist - 2",
"discount_policy": "with_discount",
"item_ids": [
(
0,
0,
{
"applied_on": "1_product",
"compute_price": "percentage",
"percent_price": 10.0,
"product_tmpl_id": cls.product.id,
},
)
],
}
)
cls.sale_pricelist_without_discount = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist - 3",
"discount_policy": "without_discount",
"item_ids": [
(
0,
0,
{
"applied_on": "1_product",
"compute_price": "percentage",
"percent_price": 10.0,
"product_tmpl_id": cls.product.id,
},
)
],
}
)
cls.euro_currency = cls.env["res.currency"].search([("name", "=", "EUR")])
cls.usd_currency = cls.env["res.currency"].search([("name", "=", "USD")])
cls.sale_pricelist_with_discount_in_euros = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist - 4",
"discount_policy": "with_discount",
"currency_id": cls.euro_currency.id,
"item_ids": [
(
0,
0,
{
"applied_on": "1_product",
"compute_price": "percentage",
"percent_price": 10.0,
"product_tmpl_id": cls.product.id,
},
)
],
}
)
cls.sale_pricelist_without_discount_in_euros = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist - 5",
"discount_policy": "without_discount",
"currency_id": cls.euro_currency.id,
"item_ids": [
(
0,
0,
{
"applied_on": "1_product",
"compute_price": "percentage",
"percent_price": 10.0,
"product_tmpl_id": cls.product.id,
},
)
],
}
)
cls.sale_pricelist_fixed_with_discount_in_euros = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist - 6",
"discount_policy": "with_discount",
"currency_id": cls.euro_currency.id,
"item_ids": [
(
0,
0,
{
"applied_on": "1_product",
"compute_price": "fixed",
"fixed_price": 60.00,
"product_tmpl_id": cls.product.id,
},
)
],
}
)
cls.sale_pricelist_fixed_wo_disc_euros = cls.ProductPricelist.create(
{
"name": "Test Sale pricelist - 7",
"discount_policy": "without_discount",
"currency_id": cls.euro_currency.id,
"item_ids": [
(
0,
0,
{
"applied_on": "1_product",
"compute_price": "fixed",
"fixed_price": 60.00,
"product_tmpl_id": cls.product.id,
},
)
],
}
)
cls.invoice = cls.AccountMove.create(
{
"partner_id": cls.partner.id,
"move_type": "out_invoice",
"invoice_line_ids": [
(
0,
0,
{
"product_id": cls.product.product_variant_ids[:1].id,
"name": "Test line",
"quantity": 1.0,
"price_unit": 100.00,
},
),
(
0,
0,
{
"product_id": cls.product.product_variant_ids[:2].id,
"name": "Test line 2",
"quantity": 1.0,
"price_unit": 100.00,
},
),
],
}
)
# Fix currency rate of EUR -> USD to 1.5289
usd_currency = cls.env["res.currency"].search([("name", "=", "USD")])
usd_rates = cls.env["res.currency.rate"].search(
[("currency_id", "=", usd_currency.id)]
)
usd_rates.unlink()
cls.env["res.currency.rate"].create(
{
"currency_id": usd_currency.id,
"rate": 1.5289,
"create_date": "2010-01-01",
"write_date": "2010-01-01",
}
)
def test_account_invoice_pricelist(self):
self.invoice._onchange_partner_id_account_invoice_pricelist()
self.assertEqual(self.invoice.pricelist_id, self.sale_pricelist)
def test_account_invoice_change_pricelist(self):
self.invoice.pricelist_id = self.sale_pricelist.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertEqual(invoice_line.price_unit, 60.00)
self.assertEqual(invoice_line.discount, 0.00)
def test_account_invoice_pricelist_without_discount(self):
self.invoice.pricelist_id = self.sale_pricelist_fixed_without_discount.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertEqual(invoice_line.price_unit, 100.00)
self.assertEqual(invoice_line.discount, 40.00)
def test_account_invoice_with_discount_change_pricelist(self):
self.invoice.pricelist_id = self.sale_pricelist_with_discount.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertEqual(invoice_line.price_unit, 90.00)
self.assertEqual(invoice_line.discount, 0.00)
def test_account_invoice_without_discount_change_pricelist(self):
self.invoice.pricelist_id = self.sale_pricelist_without_discount.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertEqual(invoice_line.price_unit, 100.00)
self.assertEqual(invoice_line.discount, 10.00)
def test_account_invoice_pricelist_with_discount_secondary_currency(self):
self.invoice.currency_id = self.euro_currency.id
self.invoice.pricelist_id = self.sale_pricelist_with_discount_in_euros.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertAlmostEqual(invoice_line.price_unit, 58.87)
self.assertEqual(invoice_line.discount, 0.00)
def test_account_invoice_pricelist_without_discount_secondary_currency(self):
self.invoice.currency_id = self.euro_currency.id
self.invoice.pricelist_id = self.sale_pricelist_without_discount_in_euros.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertAlmostEqual(invoice_line.price_unit, 65.41)
self.assertEqual(invoice_line.discount, 10.00)
def test_account_invoice_fixed_pricelist_with_discount_secondary_currency(self):
self.invoice.currency_id = self.euro_currency.id
self.invoice.pricelist_id = self.sale_pricelist_fixed_with_discount_in_euros.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertEqual(invoice_line.price_unit, 60.00)
self.assertEqual(invoice_line.discount, 0.00)
def test_account_invoice_fixed_pricelist_without_discount_secondary_currency(self):
self.invoice.currency_id = self.euro_currency.id
self.invoice.pricelist_id = self.sale_pricelist_fixed_wo_disc_euros.id
self.invoice.button_update_prices_from_pricelist()
invoice_line = self.invoice.invoice_line_ids[:1]
self.assertAlmostEqual(invoice_line.price_unit, 65.41)
self.assertEqual(invoice_line.discount, 8.27)
def test_upstream_file_hash(self):
"""Test that copied upstream function hasn't received fixes"""
func = inspect.getsource(upstream._get_real_price_currency).encode()
func_hash = hashlib.md5(func).hexdigest()
self.assertIn(func_hash, VALID_HASHES)
def test_check_currency(self):
with self.assertRaises(UserError):
self.invoice.currency_id = self.usd_currency.id
self.invoice.write(
{"pricelist_id": self.sale_pricelist_with_discount_in_euros.id}
)
| 40.577039
| 13,431
|
9,564
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class AccountMove(models.Model):
_inherit = "account.move"
pricelist_id = fields.Many2one(
comodel_name="product.pricelist",
string="Pricelist",
readonly=True,
states={"draft": [("readonly", False)]},
)
@api.constrains("pricelist_id", "currency_id")
def _check_currency(self):
for sel in self.filtered(lambda a: a.pricelist_id and a.is_invoice()):
if sel.pricelist_id.currency_id != sel.currency_id:
raise UserError(
_("Pricelist and Invoice need to use the same currency.")
)
@api.onchange("partner_id", "company_id")
def _onchange_partner_id_account_invoice_pricelist(self):
if self.is_invoice():
if (
self.partner_id
and self.move_type in ("out_invoice", "out_refund")
and self.partner_id.property_product_pricelist
):
self.pricelist_id = self.partner_id.property_product_pricelist
self._set_pricelist_currency()
@api.onchange("pricelist_id")
def _set_pricelist_currency(self):
if (
self.is_invoice()
and self.pricelist_id
and self.currency_id != self.pricelist_id.currency_id
):
self.currency_id = self.pricelist_id.currency_id
def button_update_prices_from_pricelist(self):
for inv in self.filtered(lambda r: r.state == "draft"):
inv.invoice_line_ids._onchange_product_id_account_invoice_pricelist()
self.filtered(lambda r: r.state == "draft").with_context(
check_move_validity=False
)._move_autocomplete_invoice_lines_values()
self.filtered(lambda r: r.state == "draft").with_context(
check_move_validity=False
)._recompute_tax_lines()
def _reverse_move_vals(self, default_values, cancel=True):
move_vals = super(AccountMove, self)._reverse_move_vals(
default_values, cancel=cancel
)
if self.pricelist_id:
move_vals["pricelist_id"] = self.pricelist_id.id
return move_vals
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
@api.onchange("product_id", "quantity")
def _onchange_product_id_account_invoice_pricelist(self):
for sel in self:
if not sel.move_id.pricelist_id:
return
sel.with_context(check_move_validity=False).update(
{"price_unit": sel._get_price_with_pricelist()}
)
@api.onchange("product_uom_id")
def _onchange_uom_id(self):
if (
self.move_id.is_invoice()
and self.move_id.state == "draft"
and self.move_id.pricelist_id
):
price_unit = self._get_computed_price_unit()
taxes = self._get_computed_taxes()
if taxes and self.move_id.fiscal_position_id:
price_subtotal = self._get_price_total_and_subtotal(
price_unit=price_unit, taxes=taxes
)["price_subtotal"]
accounting_vals = self._get_fields_onchange_subtotal(
price_subtotal=price_subtotal,
currency=self.move_id.company_currency_id,
)
amount_currency = accounting_vals["amount_currency"]
price_unit = self._get_fields_onchange_balance(
amount_currency=amount_currency
).get("price_unit", price_unit)
self.with_context(check_move_validity=False).update(
{"price_unit": price_unit}
)
return
else:
return super(AccountMoveLine, self)._onchange_uom_id()
def _get_real_price_currency(self, product, rule_id, qty, uom, pricelist_id):
PricelistItem = self.env["product.pricelist.item"]
field_name = "lst_price"
currency_id = None
product_currency = product.currency_id
if rule_id:
pricelist_item = PricelistItem.browse(rule_id)
while (
pricelist_item.base == "pricelist"
and pricelist_item.base_pricelist_id
and pricelist_item.base_pricelist_id.discount_policy
== "without_discount"
):
price, rule_id = pricelist_item.base_pricelist_id.with_context(
uom=uom.id
).get_product_price_rule(product, qty, self.move_id.partner_id)
pricelist_item = PricelistItem.browse(rule_id)
if pricelist_item.base == "standard_price":
field_name = "standard_price"
product_currency = product.cost_currency_id
elif (
pricelist_item.base == "pricelist" and pricelist_item.base_pricelist_id
):
field_name = "price"
product = product.with_context(
pricelist=pricelist_item.base_pricelist_id.id
)
product_currency = pricelist_item.base_pricelist_id.currency_id
currency_id = pricelist_item.pricelist_id.currency_id
if not currency_id:
currency_id = product_currency
cur_factor = 1.0
else:
if currency_id.id == product_currency.id:
cur_factor = 1.0
else:
cur_factor = currency_id._get_conversion_rate(
product_currency,
currency_id,
self.company_id or self.env.company,
self.move_id.invoice_date or fields.Date.today(),
)
product_uom = self.env.context.get("uom") or product.uom_id.id
if uom and uom.id != product_uom:
uom_factor = uom._compute_price(1.0, product.uom_id)
else:
uom_factor = 1.0
return product[field_name] * uom_factor * cur_factor, currency_id
def _calculate_discount(self, base_price, final_price):
discount = (base_price - final_price) / base_price * 100
if (discount < 0 and base_price > 0) or (discount > 0 and base_price < 0):
discount = 0.0
return discount
def _get_price_with_pricelist(self):
price_unit = 0.0
if self.move_id.pricelist_id and self.product_id and self.move_id.is_invoice():
if self.move_id.pricelist_id.discount_policy == "with_discount":
product = self.product_id.with_context(
lang=self.move_id.partner_id.lang,
partner=self.move_id.partner_id.id,
quantity=self.quantity,
date_order=self.move_id.invoice_date,
date=self.move_id.invoice_date,
pricelist=self.move_id.pricelist_id.id,
product_uom_id=self.product_uom_id.id,
fiscal_position=(
self.move_id.partner_id.property_account_position_id.id
),
)
tax_obj = self.env["account.tax"]
recalculated_price_unit = (
product.price * self.product_id.uom_id.factor
) / (self.product_uom_id.factor or 1.0)
price_unit = tax_obj._fix_tax_included_price_company(
recalculated_price_unit,
product.taxes_id,
self.tax_ids,
self.company_id,
)
self.with_context(check_move_validity=False).discount = 0.0
else:
final_price, rule_id = self.move_id.pricelist_id.with_context(
partner_id=self.move_id.partner_id.id,
date=self.move_id.invoice_date or fields.Date.today(),
uom=self.product_uom_id.id,
).get_product_price_rule(
self.product_id, self.quantity or 1.0, self.move_id.partner_id
)
base_price, currency = self.with_context(
partner_id=self.move_id.partner_id.id,
date=self.move_id.invoice_date or fields.Date.today(),
uom=self.product_uom_id.id,
)._get_real_price_currency(
self.product_id,
rule_id,
self.quantity,
self.product_uom_id,
self.move_id.pricelist_id.id,
)
if currency != self.move_id.pricelist_id.currency_id:
base_price = currency._convert(
base_price,
self.move_id.pricelist_id.currency_id,
self.move_id.company_id or self.env.company,
self.move_id.invoice_date or fields.Date.today(),
)
price_unit = max(base_price, final_price)
self.with_context(
check_move_validity=False
).discount = self._calculate_discount(base_price, final_price)
return price_unit
def _get_computed_price_unit(self):
price_unit = super(AccountMoveLine, self)._get_computed_price_unit()
if self.move_id.pricelist_id and self.move_id.is_invoice():
price_unit = self._get_price_with_pricelist()
return price_unit
| 42.318584
| 9,564
|
735
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Sale Line Refund To Invoice Qty",
"summary": """Allow deciding whether refunded quantity should be considered
as quantity to reinvoice""",
"version": "15.0.1.0.1",
"category": "Sales",
"website": "https://github.com/OCA/account-invoicing",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"license": "LGPL-3",
"application": False,
"installable": True,
"depends": ["sale_management"],
"data": [
"views/account_move_views.xml",
"views/sale_order_views.xml",
"wizards/account_move_reversal_view.xml",
],
}
| 36.75
| 735
|
3,360
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo.tests.common import TransactionCase, tagged
@tagged("post_install", "-at_install")
class TestSaleLineRefundToInvoiceQty(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner = cls.env["res.partner"].create({"name": "Test"})
cls.product = cls.env["product.product"].create(
{"name": "test_product", "type": "consu"}
)
cls.order = cls.env["sale.order"].create(
{
"partner_id": cls.partner.id,
"order_line": [
(
0,
0,
{
"name": cls.product.name,
"product_id": cls.product.id,
"product_uom_qty": 5,
"product_uom": cls.product.uom_id.id,
"price_unit": 1000.00,
},
),
],
"pricelist_id": cls.env.ref("product.list0").id,
}
)
cls.order.action_confirm()
cls.order.order_line[0].write({"qty_delivered": 5.0})
cls.order._create_invoices()
cls.invoice = cls.order.invoice_ids[0]
cls.invoice.action_post()
def move_reversal_wiz(self, move):
wizard = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=[move.id])
.create({"journal_id": move.journal_id.id})
)
return wizard
def test_refund_qty_not_to_reinvoice(self):
"""
Test that the quantities refunded are not considered as quantities to
reinvoice in the sales order line, when the boolean is checked.
"""
self.assertEqual(self.order.order_line[0].qty_invoiced, 5.0)
reversal_wizard = self.move_reversal_wiz(self.invoice)
reversal_wizard.write({"sale_qty_to_reinvoice": False})
credit_note = self.env["account.move"].browse(
reversal_wizard.reverse_moves()["res_id"]
)
for line in credit_note.line_ids:
self.assertFalse(line.sale_qty_to_reinvoice)
self.assertEqual(self.order.order_line[0].qty_invoiced, 5.0)
self.assertEqual(self.order.order_line[0].qty_to_invoice, 0.0)
self.assertEqual(self.order.order_line[0].qty_refunded_not_invoiceable, 5.0)
def test_refund_qty_to_reinvoice(self):
"""
Test that the quantities refunded are considered as quantities to
reinvoice in the sales order line, when the boolean is left unchecked.
"""
self.assertEqual(self.order.order_line[0].qty_invoiced, 5.0)
reversal_wizard = self.move_reversal_wiz(self.invoice)
credit_note = self.env["account.move"].browse(
reversal_wizard.reverse_moves()["res_id"]
)
for line in credit_note.line_ids:
self.assertTrue(line.sale_qty_to_reinvoice)
self.assertEqual(self.order.order_line[0].qty_invoiced, 0.0)
self.assertEqual(self.order.order_line[0].qty_to_invoice, 5.0)
self.assertEqual(self.order.order_line[0].qty_refunded_not_invoiceable, 0.0)
| 42.531646
| 3,360
|
903
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import fields, models
class AccountMove(models.Model):
_inherit = "account.move"
def _reverse_move_vals(self, default_values, cancel=True):
# Set the sale_qty_to_reinvoice based on the boolean from the
# reversal wizard
move_vals = super(AccountMove, self)._reverse_move_vals(
default_values, cancel=cancel
)
if self.env.context.get("sale_qty_to_reinvoice", False):
for vals in move_vals["line_ids"]:
vals[2].update({"sale_qty_to_reinvoice": True})
return move_vals
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
sale_qty_to_reinvoice = fields.Boolean(
help="Leave it marked if you will reinvoice the same sale order line",
)
| 34.730769
| 903
|
2,199
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
qty_refunded_not_invoiceable = fields.Float(
compute="_compute_qty_refunded_not_invoiceable",
string="Quantity Refunded Not Invoiceable",
digits="Product Unit of Measure",
)
@api.depends(
"invoice_lines.move_id.state",
"invoice_lines.quantity",
"untaxed_amount_to_invoice",
"invoice_lines.sale_qty_to_reinvoice",
)
def _compute_qty_invoiced(self):
res = super()._compute_qty_invoiced()
# Revert effect of refunds in invoice_qty when `sale_qty_to_reinvoice`
# is not set.
for line in self:
qty_invoiced = line.qty_invoiced
for invoice_line in line.invoice_lines:
if (
invoice_line.move_id.state != "cancel"
and invoice_line.move_id.move_type == "out_refund"
and not invoice_line.sale_qty_to_reinvoice
):
qty_invoiced += invoice_line.product_uom_id._compute_quantity(
invoice_line.quantity, line.product_uom
)
line.qty_invoiced = qty_invoiced
return res
@api.depends(
"product_uom_qty",
"invoice_lines.move_id.state",
"invoice_lines.quantity",
"invoice_lines.sale_qty_to_reinvoice",
)
def _compute_qty_refunded_not_invoiceable(self):
for line in self:
qty_ref_not_inv = 0.0
for invoice_line in line.invoice_lines:
if (
invoice_line.move_id.state != "cancel"
and invoice_line.move_id.move_type == "out_refund"
and not invoice_line.sale_qty_to_reinvoice
):
qty_ref_not_inv += invoice_line.product_uom_id._compute_quantity(
invoice_line.quantity, line.product_uom
)
line.qty_refunded_not_invoiceable = qty_ref_not_inv
| 38.578947
| 2,199
|
679
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ForgeFlow (http://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import fields, models
class AccountMoveReversal(models.TransientModel):
_inherit = "account.move.reversal"
sale_qty_to_reinvoice = fields.Boolean(
string="This credit note will be reinvoiced",
default="True",
help="Leave it marked if you will reinvoice the same sale order line "
"(standard behaviour)",
)
def reverse_moves(self):
return super(
AccountMoveReversal,
self.with_context(sale_qty_to_reinvoice=self.sale_qty_to_reinvoice),
).reverse_moves()
| 33.95
| 679
|
648
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 - TODAY, Escodoo
# Copyright (C) 2022 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Purchase Default Terms Conditions",
"summary": """
This module allows purchase default terms & conditions""",
"version": "15.0.1.0.2",
"license": "AGPL-3",
"author": "Escodoo,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"images": ["static/description/banner.png"],
"depends": [
"purchase",
],
"data": [
"views/res_config_settings.xml",
"views/res_partner_views.xml",
],
}
| 30.857143
| 648
|
2,130
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2022 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged("post_install", "-at_install")
class TestPurchase(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super(TestPurchase, cls).setUpClass()
uom_unit = cls.env.ref("uom.product_uom_unit")
cls.env.ref("uom.product_uom_hour")
cls.product_order = cls.env["product.product"].create(
{
"name": "Zed+ Antivirus",
"standard_price": 235.0,
"list_price": 280.0,
"type": "consu",
"uom_id": uom_unit.id,
"uom_po_id": uom_unit.id,
"purchase_method": "purchase",
"default_code": "PROD_ORDER",
"taxes_id": False,
}
)
cls.partner_a.write(
{"purchase_note": "Purchase Default Terms and Conditions Partner"}
)
def test_onchange_partner_id(self):
purchase_order = (
self.env["purchase.order"]
.with_context(tracking_disable=True)
.create(
{
"partner_id": self.partner_a.id,
}
)
)
purchase_order.onchange_partner_id()
PurchaseOrderLine = self.env["purchase.order.line"].with_context(
tracking_disable=True
)
PurchaseOrderLine.create(
{
"name": self.product_order.name,
"product_id": self.product_order.id,
"product_qty": 10.0,
"product_uom": self.product_order.uom_id.id,
"price_unit": self.product_order.list_price,
"order_id": purchase_order.id,
"taxes_id": False,
}
)
self.partner_a.write({"purchase_note": False})
self.env["ir.config_parameter"].set_param("purchase.use_purchase_note", "Test")
purchase_order.onchange_partner_id()
| 33.28125
| 2,130
|
687
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2022 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
from odoo.tools import is_html_empty
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
@api.onchange("partner_id", "company_id")
def onchange_partner_id(self):
if not is_html_empty(self.partner_id.purchase_note):
self.notes = self.partner_id.purchase_note
elif (
self.env["ir.config_parameter"]
.sudo()
.get_param("purchase.use_purchase_note")
):
self.notes = self.company_id.purchase_note
return super().onchange_partner_id()
| 31.227273
| 687
|
325
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 - TODAY, Marcel Savegnago - Escodoo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResCompany(models.Model):
_inherit = "res.company"
purchase_note = fields.Html(
string="Purchase Default Terms and Conditions", translate=True
)
| 25
| 325
|
552
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 - TODAY, Marcel Savegnago - Escodoo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
purchase_note = fields.Html(
related="company_id.purchase_note",
string="Purchase Terms & Conditions",
readonly=False,
)
use_purchase_note = fields.Boolean(
string="Use Purchase Default Terms & Conditions",
config_parameter="purchase.use_purchase_note",
)
| 27.6
| 552
|
317
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2022 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
purchase_note = fields.Html(
string="Purchase Default Terms and Conditions", translate=True
)
| 24.384615
| 317
|
630
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Jarsa Sistemas
# Copyright 2021 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Purchase Stock Secondary Unit",
"summary": "Get product quantities in a secondary unit",
"version": "15.0.1.0.0",
"development_status": "Beta",
"category": "stock",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Jarsa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["purchase_order_secondary_unit", "stock_secondary_unit"],
"auto_install": True,
}
| 37.058824
| 630
|
4,558
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Jarsa Sistemas
# Copyright 2021 Tecnativa - Sergio Teruel
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
import logging
from odoo.tests import Form, TransactionCase
_logger = logging.getLogger(__name__)
class TestPurchaseStockSecondaryUnit(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Active multiple units of measure security group for user
cls.env.user.groups_id = [(4, cls.env.ref("uom.group_uom").id)]
cls.warehouse = cls.env.ref("stock.warehouse0")
cls.product_uom_kg = cls.env.ref("uom.product_uom_kgm")
cls.product_uom_gram = cls.env.ref("uom.product_uom_gram")
cls.product_uom_unit = cls.env.ref("uom.product_uom_unit")
cls.ProductSecondaryUnit = cls.env["product.secondary.unit"]
cls.partner = cls.env["res.partner"].create({"name": "test - partner"})
with Form(cls.env["product.product"]) as product_form:
product_form.name = "Test"
with product_form.secondary_uom_ids.new() as secondary_uom:
secondary_uom.name = "box"
secondary_uom.uom_id = cls.product_uom_unit
secondary_uom.factor = 5.0
cls.product = product_form.save()
cls.secondary_product_uom = cls.product.secondary_uom_ids[:1]
po = cls.env["purchase.order"].new({"partner_id": cls.partner.id})
po.onchange_partner_id()
cls.purchase_order = cls.env["purchase.order"].create(
po._convert_to_write(po._cache)
)
with Form(cls.purchase_order) as po_form:
po_form.partner_id = cls.partner
po_form.company_id = cls.env.company
with po_form.order_line.new() as line:
line.product_id = cls.product
line.secondary_uom_id = cls.secondary_product_uom
line.secondary_uom_qty = 2.0
cls.purchase_order = po_form.save()
def test_confirm_purchase_order_without_secondary_uom(self):
with Form(self.purchase_order) as po_form:
with po_form.order_line.edit(0) as line:
line.secondary_uom_id = self.ProductSecondaryUnit.browse()
line.secondary_uom_qty = 0.0
self.purchase_order.button_confirm()
picking = self.purchase_order.picking_ids
self.assertEqual(picking.move_lines.secondary_uom_qty, 0.0)
self.assertFalse(picking.move_lines.secondary_uom_id)
self.assertEqual(picking.move_lines.product_uom_qty, 10.0)
def test_confirm_new_purchase_order(self):
self.purchase_order.button_confirm()
picking = self.purchase_order.picking_ids
self.assertEqual(picking.move_lines.secondary_uom_qty, 2.0)
self.assertEqual(
picking.move_lines.secondary_uom_id, self.secondary_product_uom
)
self.assertEqual(picking.move_lines.product_uom_qty, 10.0)
def test_update_confirmed_purchase_order(self):
self.purchase_order.button_confirm()
with Form(self.purchase_order) as po_form:
with po_form.order_line.edit(0) as line:
line.secondary_uom_qty = 5.0
picking = self.purchase_order.picking_ids
self.assertEqual(picking.move_lines.secondary_uom_qty, 5.0)
self.assertEqual(
picking.move_lines.secondary_uom_id, self.secondary_product_uom
)
self.assertEqual(picking.move_lines.product_uom_qty, 25.0)
def test_update_confirmed_purchase_order_with_move_validated(self):
self.purchase_order.button_confirm()
picking = self.purchase_order.picking_ids
picking.action_assign()
picking.move_line_ids.qty_done = picking.move_lines.product_uom_qty
picking.button_validate()
with Form(self.purchase_order) as po_form:
with po_form.order_line.edit(0) as line:
line.secondary_uom_qty = 5.0
picking = self.purchase_order.picking_ids.filtered(lambda p: p.state != "done")
self.assertEqual(picking.move_lines.secondary_uom_qty, 3.0)
self.assertEqual(
picking.move_lines.secondary_uom_id, self.secondary_product_uom
)
self.assertEqual(picking.move_lines.product_uom_qty, 15.0)
# Assigned move line
self.assertEqual(picking.move_line_ids.secondary_uom_qty, 3.0)
self.assertEqual(
picking.move_line_ids.secondary_uom_id, self.secondary_product_uom
)
self.assertEqual(picking.move_line_ids.product_uom_qty, 15.0)
| 46.989691
| 4,558
|
1,705
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Jarsa Sistemas
# Copyright 2021 Tecnativa - Sergio Teruel
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from odoo import models
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
def _get_secondary_uom_for_move(self, product_uom_qty):
if not self.secondary_uom_id:
return 0.0
move = self.env["stock.move"].new()
move.product_id = self.product_id
move.product_uom = self.product_uom
move.secondary_uom_id = self.secondary_uom_id
move.product_uom_qty = product_uom_qty
return move.secondary_uom_qty
def _prepare_stock_moves(self, picking):
res = super()._prepare_stock_moves(picking)
# Ensure one method.
# Compute secondary unit values for stock moves.
# When a po line with stock moves has been updated the new moves only
# have the new quantity added so we always want compute the
# secondary unit.
if res:
product_uom_qty = res[0]["product_uom_qty"]
secondary_uom_qty = self._get_secondary_uom_for_move(product_uom_qty)
res[0].update(
{
"secondary_uom_id": self.secondary_uom_id.id,
"secondary_uom_qty": secondary_uom_qty,
}
)
return res
def _create_or_update_picking(self):
# Inject a context to recompute secondary unit in stock moves after
# they have been assigned only for po lines updated and confirmed.
return super(
PurchaseOrderLine, self.with_context(secondary_uom_for_update_moves=True)
)._create_or_update_picking()
| 38.75
| 1,705
|
508
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class StockMove(models.Model):
_inherit = "stock.move"
def _action_assign(self):
res = super()._action_assign()
if self.env.context.get("secondary_uom_for_update_moves"):
for move in self:
move.secondary_uom_id = move.purchase_line_id.secondary_uom_id
move._compute_secondary_uom_qty()
return res
| 33.866667
| 508
|
748
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Purchase Order Triple Discount",
"version": "15.0.1.1.0",
"category": "Purchase Management",
"author": "Tecnativa," "GRAP," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"license": "AGPL-3",
"summary": "Manage triple discount on purchase order lines",
"depends": [
"purchase_discount",
"account_invoice_triple_discount",
],
"data": [
"views/purchase_order_report.xml",
"views/product_supplierinfo_view.xml",
"views/purchase_view.xml",
"views/res_partner_view.xml",
],
"installable": True,
}
| 34
| 748
|
9,812
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-19 Tecnativa - David Vidal
# Copyright 2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import common
from odoo.tests.common import Form
class TestPurchaseOrder(common.TransactionCase):
@classmethod
def setUpClass(cls):
super(TestPurchaseOrder, cls).setUpClass()
cls.supplierinfo_obj = cls.env["product.supplierinfo"]
cls.account_move_model = cls.env["account.move"]
cls.partner = cls.env["res.partner"].create(
{
"name": "Mr. Odoo",
}
)
cls.partner2 = cls.env["res.partner"].create(
{
"name": "Mrs. Odoo",
}
)
cls.product1 = cls.env["product.product"].create(
{
"name": "Test Product 1",
"purchase_method": "purchase",
}
)
cls.product2 = cls.env["product.product"].create(
{
"name": "Test Product 2",
"purchase_method": "purchase",
}
)
cls.supplierinfo = cls.supplierinfo_obj.create(
{
"min_qty": 0.0,
"name": cls.partner2.id,
"product_tmpl_id": cls.product1.product_tmpl_id.id,
"discount": 10,
"discount2": 20,
"discount3": 30,
}
)
cls.supplierinfo2 = cls.supplierinfo_obj.create(
{
"min_qty": 10.0,
"name": cls.partner2.id,
"product_tmpl_id": cls.product1.product_tmpl_id.id,
"discount3": 50,
}
)
cls.tax = cls.env["account.tax"].create(
{
"name": "TAX 15%",
"amount_type": "percent",
"type_tax_use": "purchase",
"amount": 15.0,
}
)
cls.order = cls.env["purchase.order"].create(
{
"partner_id": cls.partner.id,
}
)
cls.order2 = cls.env["purchase.order"].create(
{
"partner_id": cls.partner2.id,
}
)
po_line = cls.env["purchase.order.line"]
cls.po_line1 = po_line.create(
{
"order_id": cls.order.id,
"product_id": cls.product1.id,
"date_planned": "2018-01-19 00:00:00",
"name": "Line 1",
"product_qty": 1.0,
"product_uom": cls.product1.uom_id.id,
"taxes_id": [(6, 0, [cls.tax.id])],
"price_unit": 600.0,
}
)
cls.po_line2 = po_line.create(
{
"order_id": cls.order.id,
"product_id": cls.product2.id,
"date_planned": "2018-01-19 00:00:00",
"name": "Line 2",
"product_qty": 10.0,
"product_uom": cls.product2.uom_id.id,
"taxes_id": [(6, 0, [cls.tax.id])],
"price_unit": 60.0,
}
)
cls.po_line3 = po_line.create(
{
"order_id": cls.order2.id,
"product_id": cls.product1.id,
"date_planned": "2020-01-01 00:00:00",
"name": "Line 1",
"product_qty": 1.0,
"product_uom": cls.product1.uom_id.id,
"taxes_id": [(6, 0, [cls.tax.id])],
"price_unit": 600.0,
}
)
def test_01_purchase_order_classic_discount(self):
"""Tests with single discount"""
self.po_line1.discount = 50.0
self.po_line2.discount = 75.0
self.assertEqual(self.po_line1.price_subtotal, 300.0)
self.assertEqual(self.po_line2.price_subtotal, 150.0)
self.assertEqual(self.order.amount_untaxed, 450.0)
self.assertEqual(self.order.amount_tax, 67.5)
# Mix taxed and untaxed:
self.po_line1.taxes_id = False
self.assertEqual(self.order.amount_tax, 22.5)
def test_02_purchase_order_simple_triple_discount(self):
"""Tests on a single line"""
self.po_line2.unlink()
# Divide by two on every discount:
self.po_line1.discount = 50.0
self.po_line1.discount2 = 50.0
self.po_line1.discount3 = 50.0
self.assertEqual(self.po_line1.price_subtotal, 75.0)
self.assertEqual(self.order.amount_untaxed, 75.0)
self.assertEqual(self.order.amount_tax, 11.25)
# Unset first discount:
self.po_line1.discount = 0.0
self.assertEqual(self.po_line1.price_subtotal, 150.0)
self.assertEqual(self.order.amount_untaxed, 150.0)
self.assertEqual(self.order.amount_tax, 22.5)
# Set a charge instead:
self.po_line1.discount2 = -50.0
self.assertEqual(self.po_line1.price_subtotal, 450.0)
self.assertEqual(self.order.amount_untaxed, 450.0)
self.assertEqual(self.order.amount_tax, 67.5)
def test_03_purchase_order_complex_triple_discount(self):
"""Tests on multiple lines"""
self.po_line1.discount = 50.0
self.po_line1.discount2 = 50.0
self.po_line1.discount3 = 50.0
self.assertEqual(self.po_line1.price_subtotal, 75.0)
self.assertEqual(self.order.amount_untaxed, 675.0)
self.assertEqual(self.order.amount_tax, 101.25)
self.po_line2.discount3 = 50.0
self.assertEqual(self.po_line2.price_subtotal, 300.0)
self.assertEqual(self.order.amount_untaxed, 375.0)
self.assertEqual(self.order.amount_tax, 56.25)
def test_04_purchase_order_triple_discount_invoicing(self):
"""When a confirmed order is invoiced, the resultant invoice
should inherit the discounts"""
self.po_line1.discount = 50.0
self.po_line1.discount2 = 50.0
self.po_line1.discount3 = 50.0
self.po_line2.discount3 = 50.0
self.order.button_confirm()
invoice_form = Form(
self.account_move_model.with_context(default_move_type="in_invoice")
)
invoice_form.partner_id = self.order.partner_id
invoice_form.purchase_id = self.order
self.invoice = invoice_form.save()
self.assertEqual(
self.po_line1.discount, self.invoice.invoice_line_ids[0].discount
)
self.assertEqual(
self.po_line1.discount2, self.invoice.invoice_line_ids[0].discount2
)
self.assertEqual(
self.po_line1.discount3, self.invoice.invoice_line_ids[0].discount3
)
self.assertEqual(
self.po_line2.discount3, self.invoice.invoice_line_ids[1].discount3
)
self.assertEqual(self.order.amount_total, self.invoice.amount_total)
def test_05_purchase_order_default_discounts(self):
self.po_line3._onchange_quantity()
self.assertEqual(self.po_line3.discount, 10)
self.assertEqual(self.po_line3.discount2, 20)
self.assertEqual(self.po_line3.discount3, 30)
self.po_line3.product_qty = 10
self.po_line3._onchange_quantity()
self.assertFalse(self.po_line3.discount)
self.assertFalse(self.po_line3.discount2)
self.assertEqual(self.po_line3.discount3, 50)
def test_06_default_supplier_discounts(self):
self.partner2.default_supplierinfo_discount = 11
self.partner2.default_supplierinfo_discount2 = 22
self.partner2.default_supplierinfo_discount3 = 33
supplierinfo = self.supplierinfo_obj.new(
{
"min_qty": 0.0,
"name": self.partner2.id,
"product_tmpl_id": self.product1.product_tmpl_id.id,
"discount": 10,
}
)
supplierinfo.onchange_name()
self.assertEqual(supplierinfo.discount, 11)
self.assertEqual(supplierinfo.discount2, 22)
self.assertEqual(supplierinfo.discount3, 33)
def test_07_supplierinfo_from_purchaseorder(self):
self.order2.order_line.create(
{
"order_id": self.order2.id,
"product_id": self.product2.id,
"date_planned": "2020-01-01 00:00:00",
"name": "Line 2",
"product_qty": 1.0,
"product_uom": self.product2.uom_id.id,
"taxes_id": [(6, 0, [self.tax.id])],
"price_unit": 999.0,
"discount": 11.11,
"discount2": 22.22,
"discount3": 33.33,
}
)
self.order2.button_confirm()
seller = self.supplierinfo_obj.search(
[
("name", "=", self.partner2.id),
("product_tmpl_id", "=", self.product2.product_tmpl_id.id),
]
)
self.assertTrue(seller)
self.assertEqual(seller.discount, 11.11)
self.assertEqual(seller.discount2, 22.22)
self.assertEqual(seller.discount3, 33.33)
def test_08_purchase_report(self):
self.po_line2.write(
{
"discount2": 50,
"discount3": 20,
}
)
self.order.currency_id.rate_ids.unlink() # for avoiding rate convers.
rec = self.env["purchase.report"].search(
[
("product_id", "=", self.product2.id),
]
)
self.assertEqual(rec.discount2, 50)
self.assertEqual(rec.discount3, 20)
# Changes value of comparison,
# because currently include taxes on field price_total
# https://bit.ly/3Hv2bEX
# https://bit.ly/3ESkdiO
self.assertEqual(self.po_line2.price_tax, 36)
self.assertEqual(rec.price_total, 276)
| 37.59387
| 9,812
|
1,046
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 Tecnativa - David Vidal
# Copyright 2019 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductSupplierInfo(models.Model):
_inherit = "product.supplierinfo"
discount2 = fields.Float(
string="Discount 2 (%)",
digits="Discount",
)
discount3 = fields.Float(
string="Discount 3 (%)",
digits="Discount",
)
@api.onchange("name")
def onchange_name(self):
"""Apply the default supplier discounts of the selected supplier"""
for supplierinfo in self.filtered("name"):
supplierinfo.discount2 = supplierinfo.name.default_supplierinfo_discount2
supplierinfo.discount3 = supplierinfo.name.default_supplierinfo_discount3
return super().onchange_name()
@api.model
def _get_po_to_supplierinfo_synced_fields(self):
res = super()._get_po_to_supplierinfo_synced_fields()
res += ["discount2", "discount3"]
return res
| 33.741935
| 1,046
|
1,712
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-19 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
# adding discount2 and discount3 to depends
@api.depends("discount2", "discount3")
def _compute_amount(self):
return super()._compute_amount()
discount2 = fields.Float(
"Disc. 2 (%)",
digits="Discount",
)
discount3 = fields.Float(
"Disc. 3 (%)",
digits="Discount",
)
_sql_constraints = [
(
"discount2_limit",
"CHECK (discount2 <= 100.0)",
"Discount 2 must be lower than 100%.",
),
(
"discount3_limit",
"CHECK (discount3 <= 100.0)",
"Discount 3 must be lower than 100%.",
),
]
def _get_discounted_price_unit(self):
price_unit = super()._get_discounted_price_unit()
if self.discount2:
price_unit *= 1 - self.discount2 / 100.0
if self.discount3:
price_unit *= 1 - self.discount3 / 100.0
return price_unit
@api.model
def _apply_value_from_seller(self, seller):
super()._apply_value_from_seller(seller)
if not seller:
return
self.discount2 = seller.discount2
self.discount3 = seller.discount3
def _prepare_account_move_line(self, move=False):
self.ensure_one()
res = super()._prepare_account_move_line(move)
res.update(
{
"discount2": self.discount2,
"discount3": self.discount3,
}
)
return res
| 27.612903
| 1,712
|
729
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
default_supplierinfo_discount2 = fields.Float(
string="Default Supplier Discount 2 (%)",
digits="Discount",
help="This value will be used as the default one, for each new "
"supplierinfo line depending on that supplier.",
)
default_supplierinfo_discount3 = fields.Float(
string="Default Supplier Discount 3 (%)",
digits="Discount",
help="This value will be used as the default one, for each new "
"supplierinfo line depending on that supplier.",
)
| 36.45
| 729
|
1,288
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 GRAP (http://www.grap.coop)
# Sylvain LE GAL (https://twitter.com/legalsylvain)
# Copyright 2019 Tecnativa - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import fields, models
class PurchaseReport(models.Model):
_inherit = "purchase.report"
discount2 = fields.Float(
string="Discount 2 (%)",
digits="Discount",
group_operator="avg",
)
discount3 = fields.Float(
string="Discount 3 (%)",
digits="Discount",
group_operator="avg",
)
def _select(self):
res = super()._select()
res += ", l.discount2 AS discount2, l.discount3 AS discount3"
return res
def _group_by(self):
res = super()._group_by()
res += ", l.discount2, l.discount3"
return res
def _get_discounted_price_unit_exp(self):
"""Inheritable method for getting the SQL expression used for
calculating the unit price with discount(s).
:rtype: str
:return: SQL expression for discounted unit price.
"""
return """
((100 - COALESCE(l.discount, 0.0)) *
(100 - COALESCE(l.discount2, 0.0)) *
(100 - COALESCE(l.discount3, 0.0))) / 1000000 * l.price_unit"""
| 29.953488
| 1,288
|
611
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Purchase Order security",
"version": "15.0.2.0.0",
"category": "Purchase",
"development_status": "Production/Stable",
"author": "Tecnativa, Odoo Community Association (OCA)",
"summary": "See only your purchase orders",
"website": "https://github.com/OCA/purchase-workflow",
"license": "AGPL-3",
"depends": ["purchase"],
"maintainers": ["pilarvargas-tecnativa"],
"data": ["security/security.xml", "views/purchase_order_views.xml"],
"installable": True,
"auto_install": False,
}
| 35.941176
| 611
|
4,345
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
from odoo.tests.common import TransactionCase
_logger = logging.getLogger(__name__)
class TestPurchaseOrderSecurity(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestPurchaseOrderSecurity, cls).setUpClass()
# Users
users = cls.env["res.users"].with_context(no_reset_password=True)
group_name = "group_purchase_own_orders"
# User in group_purchase_own_orders
cls.user_group_purchase_own_orders = users.create(
{
"name": "group_purchase_own_orders",
"login": "group_purchase_own_orders",
"email": "group_purchase_own_orders@example.com",
"groups_id": [
(6, 0, [cls.env.ref("purchase_security.%s" % group_name).id])
],
}
)
# Purchase order user
cls.user_po_user = users.create(
{
"name": "po_user",
"login": "po_user",
"email": "po_user@example.com",
"groups_id": [(6, 0, [cls.env.ref("purchase.group_purchase_user").id])],
}
)
# Purchase order manager
cls.user_po_manager = users.create(
{
"name": "po_manager",
"login": "po_manager",
"email": "po_manager@example.com",
"groups_id": [
(6, 0, [cls.env.ref("purchase.group_purchase_manager").id])
],
}
)
# User without groups
cls.user_without_groups = users.create(
{
"name": "without_groups",
"login": "without_groups",
"email": "without_groups@example.com",
"groups_id": False,
}
)
# Partner for the POs
cls.partner_po = cls.env["res.partner"].create({"name": "PO Partner"})
# Purchase Order
cls.env["purchase.order"].create(
(
{
"name": "po_security_1",
"partner_id": cls.partner_po.id,
"user_id": False, # No Purchase Representative
},
{
"name": "po_security_2",
"user_id": cls.user_po_user.id,
"partner_id": cls.partner_po.id,
},
{
"name": "po_security_3",
"user_id": cls.user_po_manager.id,
"partner_id": cls.partner_po.id,
},
{
"name": "po_security_4",
"user_id": cls.user_group_purchase_own_orders.id,
"partner_id": cls.partner_po.id,
},
)
)
def test_access_user_user_group_purchase_own_orders(self):
# User in group should have access to it's own PO
# and to those w/o Purchase Representative
self.assertEqual(
len(
self.env["purchase.order"]
.with_user(self.user_group_purchase_own_orders)
.search([])
.ids
),
2,
)
def test_access_user_po_user(self):
# Normal PO user should have access to all of them
# because he is not in group
self.assertEqual(
len(
self.env["purchase.order"]
.with_user(self.user_po_user)
.search([("name", "like", "po_security")])
.ids
),
4,
)
def test_access_user_po_manager(self):
# Manager PO user should have access to all of them
self.assertEqual(
len(
self.env["purchase.order"]
.with_user(self.user_po_manager)
.search([("name", "like", "po_security")])
.ids
),
4,
)
def test_access_user_without_groups(self):
# User without groups should not have access to POs
self.assertEqual(
len(self.env["purchase.order"].with_user(self.user_without_groups).read()),
0,
)
| 33.666667
| 4,343
|
614
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2021 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Purchase Order Line Menu",
"version": "15.0.1.0.0",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"summary": "Adds Purchase Order Lines Menu",
"website": "https://github.com/OCA/purchase-workflow",
"license": "AGPL-3",
"depends": ["purchase"],
"category": "Inventory/Purchase",
"data": [
"views/purchase_order_line_views.xml",
],
"installable": True,
"maintainer": "dreispt",
"development_status": "Beta",
}
| 32.315789
| 614
|
760
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Akretion (http://www.akretion.com)
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Purchase Exception",
"summary": "Custom exceptions on purchase order",
"version": "15.0.1.0.0",
"category": "Generic Modules/Purchase",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase", "base_exception"],
"license": "AGPL-3",
"data": [
"security/ir.model.access.csv",
"data/purchase_exception_data.xml",
"wizard/purchase_exception_confirm_view.xml",
"views/purchase_view.xml",
],
"installable": True,
}
| 36.190476
| 760
|
4,937
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from datetime import datetime
from odoo.tests.common import TransactionCase
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
class TestPurchaseException(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Useful models
cls.PurchaseOrder = cls.env["purchase.order"]
cls.PurchaseOrderLine = cls.env["purchase.order.line"]
cls.partner_id = cls.env.ref("base.res_partner_1")
cls.product_id_1 = cls.env.ref("product.product_product_6")
cls.product_id_2 = cls.env.ref("product.product_product_7")
cls.product_id_3 = cls.env.ref("product.product_product_7")
cls.date_planned = datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT)
cls.purchase_exception_confirm = cls.env["purchase.exception.confirm"]
cls.exception_noemail = cls.env.ref("purchase_exception.po_excep_no_email")
cls.exception_qtycheck = cls.env.ref("purchase_exception.pol_excep_qty_check")
cls.po_vals = {
"partner_id": cls.partner_id.id,
"order_line": [
(
0,
0,
{
"name": cls.product_id_1.name,
"product_id": cls.product_id_1.id,
"product_qty": 5.0,
"product_uom": cls.product_id_1.uom_po_id.id,
"price_unit": 500.0,
"date_planned": cls.date_planned,
},
),
(
0,
0,
{
"name": cls.product_id_2.name,
"product_id": cls.product_id_2.id,
"product_qty": 5.0,
"product_uom": cls.product_id_2.uom_po_id.id,
"price_unit": 250.0,
"date_planned": cls.date_planned,
},
),
],
}
def test_purchase_order_exception(self):
self.exception_noemail.active = True
self.exception_qtycheck.active = True
self.partner_id.email = False
self.po = self.PurchaseOrder.create(self.po_vals.copy())
# confirm quotation
self.po.button_confirm()
self.assertEqual(self.po.state, "draft")
# test all draft po
self.po2 = self.PurchaseOrder.create(self.po_vals.copy())
self.PurchaseOrder.test_all_draft_orders()
self.assertEqual(self.po2.state, "draft")
# Set ignore_exception flag (Done after ignore is selected at wizard)
self.po.ignore_exception = True
self.po.button_confirm()
self.assertEqual(self.po.state, "purchase")
# Add a order line to test after PO is confirmed
# set ignore_exception = False (Done by onchange of order_line)
field_onchange = self.PurchaseOrder._onchange_spec()
self.assertEqual(field_onchange.get("order_line"), "1")
self.env.cache.invalidate()
self.po3New = self.PurchaseOrder.new(self.po_vals.copy())
self.po3New.ignore_exception = True
self.po3New.state = "purchase"
self.po3New.onchange_ignore_exception()
self.assertFalse(self.po3New.ignore_exception)
self.po.write(
{
"order_line": [
(
0,
0,
{
"name": self.product_id_3.name,
"product_id": self.product_id_3.id,
"product_qty": 2,
"product_uom": self.product_id_3.uom_id.id,
"price_unit": 30,
"date_planned": self.date_planned,
},
)
]
}
)
# Set ignore exception True (Done manually by user)
self.po.ignore_exception = True
self.po.button_cancel()
self.po.button_draft()
self.assertEqual(self.po.state, "draft")
self.assertTrue(not self.po.ignore_exception)
self.po.button_confirm()
self.assertTrue(self.po.state, "to approve")
# Simulation the opening of the wizard purchase_exception_confirm and
# set ignore_exception to True
po_except_confirm = self.purchase_exception_confirm.with_context(
active_id=self.po.id,
active_ids=[self.po.id],
active_model=self.po._name,
).create({"ignore": True})
po_except_confirm.action_confirm()
self.assertTrue(self.po.ignore_exception)
| 40.801653
| 4,937
|
784
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class PurchaseExceptionConfirm(models.TransientModel):
_name = "purchase.exception.confirm"
_description = "Purchase exception wizard"
_inherit = ["exception.rule.confirm"]
related_model_id = fields.Many2one("purchase.order", "Purchase")
def action_confirm(self):
self.ensure_one()
if self.ignore:
self.related_model_id.button_draft()
self.related_model_id.ignore_exception = True
self.related_model_id.button_confirm()
return super().action_confirm()
| 35.636364
| 784
|
805
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class PurchaseOrderLine(models.Model):
_inherit = ["purchase.order.line", "base.exception.method"]
_name = "purchase.order.line"
ignore_exception = fields.Boolean(
related="order_id.ignore_exception", store=True, string="Ignore Exceptions"
)
def _get_main_records(self):
return self.mapped("order_id")
@api.model
def _reverse_field(self):
return "purchase_ids"
def _detect_exceptions(self, rule):
records = super()._detect_exceptions(rule)
return records.mapped("order_id")
| 30.961538
| 805
|
1,841
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models
class PurchaseOrder(models.Model):
_inherit = ["purchase.order", "base.exception"]
_name = "purchase.order"
_order = "main_exception_id asc, date_order desc, name desc"
@api.model
def test_all_draft_orders(self):
order_set = self.search([("state", "=", "draft")])
order_set.detect_exceptions()
return True
@api.model
def _reverse_field(self):
return "purchase_ids"
def detect_exceptions(self):
all_exceptions = super().detect_exceptions()
lines = self.mapped("order_line")
all_exceptions += lines.detect_exceptions()
return all_exceptions
@api.constrains("ignore_exception", "order_line", "state")
def purchase_check_exception(self):
orders = self.filtered(lambda s: s.state == "purchase")
if orders:
orders._check_exception()
@api.onchange("order_line")
def onchange_ignore_exception(self):
if self.state == "purchase":
self.ignore_exception = False
def button_confirm(self):
if self.detect_exceptions() and not self.ignore_exception:
return self._popup_exceptions()
return super().button_confirm()
def button_draft(self):
res = super().button_draft()
for order in self:
order.exception_ids = False
order.main_exception_id = False
order.ignore_exception = False
return res
@api.model
def _get_popup_action(self):
action = self.env.ref("purchase_exception.action_purchase_exception_confirm")
return action
| 32.298246
| 1,841
|
668
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Akretion (http://www.akretion.com)
# Copyright 2020 Camptocamp SA
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ExceptionRule(models.Model):
_inherit = "exception.rule"
purchase_ids = fields.Many2many(comodel_name="purchase.order", string="Purchases")
model = fields.Selection(
selection_add=[
("purchase.order", "Purchase order"),
("purchase.order.line", "Purchase order line"),
],
ondelete={"purchase.order": "cascade", "purchase.order.line": "cascade"},
)
| 35.157895
| 668
|
596
|
py
|
PYTHON
|
15.0
|
# © 2014 Today Akretion
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# @author Pierrick Brun <pierrick.brun@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Quick Purchase order",
"version": "15.0.1.0.0",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"license": "AGPL-3",
"category": "Purchase",
"depends": ["base_product_mass_addition", "purchase"],
"data": ["views/purchase_view.xml", "views/product_view.xml"],
"installable": True,
}
| 37.125
| 594
|
9,462
|
py
|
PYTHON
|
15.0
|
# @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.exceptions import AccessError, ValidationError
from odoo.tests.common import Form, TransactionCase
class TestQuickPurchase(TransactionCase):
@classmethod
def _add_seller(cls, product, prices):
# drop existing seller
product.seller_ids.filtered(lambda s: s.name == cls.partner).unlink()
for min_qty, price in prices:
cls.env["product.supplierinfo"].create(
{
"product_tmpl_id": product.product_tmpl_id.id,
"name": cls.partner.id,
"price": price,
"min_qty": min_qty,
}
)
@classmethod
def _setUpBasicSaleOrder(cls):
vals = {"partner_id": cls.partner.id}
if hasattr(cls.env["purchase.order"], "order_type"):
vals["order_type"] = cls.env.ref("purchase_order_type.po_type_blanket").id
cls.po = cls.env["purchase.order"].create(vals)
with Form(cls.po, "purchase.purchase_order_form") as po_form:
po_form.partner_id = cls.partner
ctx = {"parent_id": cls.po.id, "parent_model": "purchase.order"}
cls.product_1 = cls.product_1.with_context(**ctx)
cls.product_2 = cls.product_2.with_context(**ctx)
cls.product_1.qty_to_process = 5.0
cls.product_2.qty_to_process = 6.0
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner = cls.env.ref("base.res_partner_1")
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
cls.uom_dozen = cls.env.ref("uom.product_uom_dozen")
cls.user = cls.env.ref("base.user_demo")
cls.product_1 = cls.env.ref("product.product_product_8")
cls.product_2 = cls.env.ref("product.product_product_11")
cls._add_seller(cls.product_1, [(0, 10), (10, 8)])
cls._add_seller(cls.product_2, [(0, 5), (10, 4)])
cls._setUpBasicSaleOrder()
def test_product_seller_price(self):
self.assertEqual(self.product_1.seller_price, 10)
self.product_1.qty_to_process = 10.0
self.assertEqual(self.product_1.seller_price, 8)
self.product_1.quick_uom_id = self.uom_dozen
self.assertEqual(self.product_1.seller_price, 96)
def test_product_seller_price_with_currency(self):
self.po.currency_id = self.env.ref("base.EUR")
usd = self.env.ref("base.USD")
usd.rate_ids[1:].unlink()
usd.rate_ids.name = self.po.date_order.date()
usd.rate_ids.rate = 2
self.assertEqual(self.product_1.seller_price, 5)
self.product_1.qty_to_process = 10.0
self.assertEqual(self.product_1.seller_price, 4)
self.product_1.quick_uom_id = self.uom_dozen
self.assertEqual(self.product_1.seller_price, 48)
def test_quick_line_add_1(self):
"""
set non-null quantity to any product with no PO line:
-> a new PO line is created with that quantity
"""
line_1, line_2 = self.po.order_line
self.assertAlmostEqual(line_1.product_uom_qty, 5.0)
self.assertAlmostEqual(line_1.price_unit, 10)
self.assertAlmostEqual(line_2.product_uom_qty, 6.0)
self.assertAlmostEqual(line_2.price_unit, 5)
def test_quick_line_add_2(self):
"""
same as previous, but include a different UoM as well
We duplicate _setUpBasicSaleOrder except we ~simultaneously~
write on qty_to_process as well as quick_uom_id
(we want to make sure to test _inverse function when it is triggered twice)
"""
vals = {"partner_id": self.partner.id}
if hasattr(self.env["purchase.order"], "order_type"):
vals["order_type"] = self.env.ref("purchase_order_type.po_type_blanket").id
po = self.env["purchase.order"].create(vals)
with Form(po, "purchase.purchase_order_form") as po_form:
po_form.partner_id = self.partner
ctx = {"parent_id": self.po.id, "parent_model": "purchase.order"}
self.product_1 = self.product_1.with_context(**ctx)
self.product_2 = self.product_2.with_context(**ctx)
self.product_1.write({"qty_to_process": 5.0, "quick_uom_id": self.uom_unit.id})
self.product_2.write({"qty_to_process": 6.0, "quick_uom_id": self.uom_dozen.id})
line_1, line_2 = self.po.order_line
self.assertAlmostEqual(line_1.product_uom_qty, 5.0)
self.assertAlmostEqual(line_1.product_qty, 5.0)
self.assertEqual(line_1.product_uom, self.uom_unit)
self.assertAlmostEqual(line_1.price_unit, 10)
self.assertAlmostEqual(line_2.product_uom_qty, 72.0) # 12 * 6
self.assertAlmostEqual(line_2.product_qty, 6.0)
self.assertEqual(line_2.product_uom, self.uom_dozen)
self.assertAlmostEqual(line_2.price_unit, 48) # 12 * 4
def test_quick_line_update_1(self):
"""
set non-null quantity to any product with an already existing PO line:
-> same PO line is updated with that quantity
"""
self.product_1.qty_to_process = 7.0
self.product_2.qty_to_process = 13.0
line_1, line_2 = self.po.order_line
self.assertAlmostEqual(line_1.product_qty, 7.0)
self.assertAlmostEqual(line_1.price_unit, 10.0)
self.assertAlmostEqual(line_2.product_qty, 13.0)
self.assertAlmostEqual(line_2.price_unit, 4.0)
def test_quick_line_update_2(self):
"""
same as previous update only UoM in isolation, not qty
"""
self.product_1.quick_uom_id = self.uom_dozen
self.product_2.quick_uom_id = self.uom_unit
line_1, line_2 = self.po.order_line
self.assertEqual(line_1.product_uom, self.uom_dozen)
self.assertAlmostEqual(line_1.product_qty, 5.0)
self.assertAlmostEqual(line_1.product_uom_qty, 60.0)
self.assertAlmostEqual(line_1.price_unit, 96)
self.assertEqual(line_2.product_uom, self.uom_unit)
self.assertAlmostEqual(line_2.product_qty, 6.0)
self.assertAlmostEqual(line_2.product_uom_qty, 6.0)
self.assertAlmostEqual(line_2.price_unit, 5.0)
def test_quick_line_update_3(self):
"""
same as previous 2 tests combined: we do simultaneous qty + uom updates
"""
self.product_1.qty_to_process = 7.0
self.product_2.qty_to_process = 13.0
self.product_1.quick_uom_id = self.uom_dozen
self.product_2.quick_uom_id = self.uom_unit
line_1, line_2 = self.po.order_line
self.assertEqual(line_1.product_uom, self.uom_dozen)
self.assertEqual(line_2.product_uom, self.uom_unit)
self.assertEqual(line_1.product_uom, self.uom_dozen)
self.assertAlmostEqual(line_1.product_qty, 7.0)
self.assertAlmostEqual(line_1.product_uom_qty, 84.0)
self.assertAlmostEqual(line_1.price_unit, 96)
self.assertEqual(line_2.product_uom, self.uom_unit)
self.assertAlmostEqual(line_2.product_qty, 13.0)
self.assertAlmostEqual(line_2.product_uom_qty, 13.0)
self.assertAlmostEqual(line_2.price_unit, 4.0)
def test_quick_line_delete(self):
"""
set null quantity to any product with existing PO line:
-> PO line is deleted
"""
self.product_1.qty_to_process = 0.0
self.product_2.qty_to_process = 0.0
self.assertEqual(len(self.po.order_line), 0)
def test_open_quick_view(self):
"""
Test that the "Add" button opens the right action
"""
product_act_from_po = self.po.add_product()
self.assertEqual(product_act_from_po["type"], "ir.actions.act_window")
self.assertEqual(product_act_from_po["res_model"], "product.product")
self.assertEqual(product_act_from_po["view_mode"], "tree")
self.assertEqual(product_act_from_po["target"], "current")
self.assertEqual(
product_act_from_po["view_id"][0],
self.env.ref("purchase_quick.product_tree_view4purchase").id,
)
self.assertEqual(product_act_from_po["context"]["parent_id"], self.po.id)
def test_several_po_for_one_product(self):
"""
Test that when we try to mass add a product that already has
several lines with the same product we get a raise
"""
self.po.order_line[0].copy()
with self.assertRaises(ValidationError):
self.product_1.qty_to_process = 3.0
def test_purchaser_can_edit_products(self):
"""
While in the quick purchase interface, a purchaser with no edit rights
on product.product can still edit product.product quick quantities
"""
po = self.env["purchase.order"].create({"partner_id": self.partner.id})
ctx = {
"parent_id": po.id,
"parent_model": "purchase.order",
"quick_access_rights_purchase": 1,
}
product = self.env.ref("product.product_product_8")
with self.assertRaises(AccessError):
product.with_user(self.user).write(
{"qty_to_process": 5.0, "quick_uom_id": self.uom_unit.id}
)
product_in_quick_edit = product.with_user(self.user).with_context(**ctx)
product_in_quick_edit.write(
{"qty_to_process": 5.0, "quick_uom_id": self.uom_unit.id}
)
| 43.805556
| 9,462
|
2,471
|
py
|
PYTHON
|
15.0
|
# © 2014 Today Akretion
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# @author Pierrick Brun <pierrick.brun@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import _, models
from odoo.exceptions import ValidationError
class PurchaseOrder(models.Model):
_name = "purchase.order"
_inherit = ["purchase.order", "product.mass.addition"]
def add_product(self):
self.ensure_one()
res = self._common_action_keys()
res["context"].update(
{
"search_default_filter_to_purchase": 1,
"search_default_filter_for_current_supplier": 1,
"quick_access_rights_purchase": 1,
}
)
commercial = self.partner_id.commercial_partner_id.name
res["name"] = "🔙 {} ({})".format(_("Product Variants"), commercial)
res["view_id"] = (self.env.ref("purchase_quick.product_tree_view4purchase").id,)
res["search_view_id"] = (
self.env.ref("purchase_quick.product_search_form_view").id,
)
return res
def _get_quick_line(self, product):
result = self.env["purchase.order.line"].search(
[("product_id", "=", product.id), ("order_id", "=", self.id)]
)
nr_lines = len(result.ids)
if nr_lines > 1:
raise ValidationError(
_(
"Must have only 1 line per product for mass addition, but "
"there are {} lines for the product {}"
).format(nr_lines, product.display_name),
)
return result
def _get_quick_line_qty_vals(self, product):
return {
"product_uom": product.quick_uom_id.id,
"product_qty": product.qty_to_process,
}
def _complete_quick_line_vals(self, vals, lines_key=""):
# This params are need for playing correctly the onchange
vals_to_add = {
"order_id": self.id,
"partner_id": self.partner_id.id,
}
vals_to_add.update(vals)
vals = vals_to_add
return super(PurchaseOrder, self)._complete_quick_line_vals(
vals, lines_key="order_line"
)
def _add_quick_line(self, product, lines_key=""):
return super(PurchaseOrder, self)._add_quick_line(
product, lines_key="order_line"
)
| 36.264706
| 2,466
|
3,750
|
py
|
PYTHON
|
15.0
|
# © 2014 Today Akretion
# @author Sébastien BEAU <sebastien.beau@akretion.com>
# @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
# @author Pierrick Brun <pierrick.brun@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class ProductProduct(models.Model):
_inherit = "product.product"
# for searching purpose
variant_specific_seller_ids = fields.One2many("product.supplierinfo", "product_id")
po_line_ids = fields.One2many(
comodel_name="purchase.order.line",
inverse_name="product_id",
help="Technical: used to compute quantities to purchase.",
)
seller_price = fields.Float(compute="_compute_seller_price")
def _compute_seller_price(self):
po = self.pma_parent
for record in self:
seller = record._select_seller(
partner_id=po.partner_id,
quantity=record.qty_to_process or 1,
uom_id=record.quick_uom_id,
)
price_unit = record.uom_id._compute_price(
seller.price,
record.quick_uom_id,
)
if self.pma_parent.currency_id != seller.currency_id:
price_unit = seller.currency_id._convert(
price_unit, po.currency_id, po.company_id, po.date_order.date()
)
record.seller_price = price_unit
def _default_quick_uom_id(self):
if self.env.context.get("parent_model", False) == "purchase.order":
return self.uom_po_id
return super()._default_quick_uom_id()
def _compute_process_qty_purchase(self):
po_lines = self.env["purchase.order.line"].search(
[("order_id", "=", self.env.context.get("parent_id"))]
)
for product in self:
product.qty_to_process = sum(
po_lines.filtered(lambda l: l.product_id == product).mapped(
"product_qty"
)
)
@api.depends("po_line_ids")
def _compute_process_qty(self):
res = super(ProductProduct, self)._compute_process_qty()
if self.env.context.get("parent_model", False) == "purchase.order":
self._compute_process_qty_purchase()
return res
@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
purchase = self.env["purchase.order"].browse(self.env.context.get("parent_id"))
if self.env.context.get("in_current_parent") and purchase:
po_lines = self.env["purchase.order.line"].search(
[("order_id", "=", purchase.id)]
)
args.append(("id", "in", po_lines.mapped("product_id").ids))
if self.env.context.get("for_current_supplier") and purchase:
seller = purchase.partner_id
seller = seller.commercial_partner_id or seller
args += [
"|",
("variant_specific_seller_ids.name", "=", seller.id),
"&",
("seller_ids.name", "=", seller.id),
("product_variant_ids", "!=", False),
]
return super(ProductProduct, self).search(
args, offset=offset, limit=limit, order=order, count=count
)
@api.model
def check_access_rights(self, operation, raise_exception=True):
"""hijack product edition rights if we're in the mass edition menu"""
if self.env.context.get("quick_access_rights_purchase"):
return self.env["purchase.order.line"].check_access_rights(
operation, raise_exception
)
return super().check_access_rights(operation, raise_exception)
| 40.301075
| 3,748
|
603
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Purchase Tier Validation",
"summary": "Extends the functionality of Purchase Orders to "
"support a tier validation process.",
"version": "15.0.1.0.0",
"category": "Purchases",
"website": "https://github.com/OCA/purchase-workflow",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["purchase", "base_tier_validation"],
"data": ["views/purchase_order_view.xml"],
}
| 37.6875
| 603
|
674
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class TierValidationTester(models.Model):
_name = "tier.validation.tester"
_description = "Tier Validation Tester"
_inherit = ["tier.validation"]
state = fields.Selection(
selection=[
("draft", "Draft"),
("confirmed", "Confirmed"),
("cancel", "Cancel"),
],
default="draft",
)
test_field = fields.Float()
user_id = fields.Many2one(string="Assigned to:", comodel_name="res.users")
def action_confirm(self):
self.write({"state": "confirmed"})
| 28.083333
| 674
|
2,371
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 ForgeFlow S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo_test_helper import FakeModelLoader
from odoo.tests import common
from odoo.tests.common import tagged
@tagged("post_install", "-at_install")
class TestPurchaseTierValidation(common.TransactionCase):
@classmethod
def setUpClass(cls):
super(TestPurchaseTierValidation, cls).setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
from .tier_validation_tester import TierValidationTester
cls.loader.update_registry((TierValidationTester,))
cls.test_model = cls.env[TierValidationTester._name]
cls.tester_model = cls.env["ir.model"].search(
[("model", "=", "tier.validation.tester")]
)
# Access record:
cls.env["ir.model.access"].create(
{
"name": "access.tester",
"model_id": cls.tester_model.id,
"perm_read": 1,
"perm_write": 1,
"perm_create": 1,
"perm_unlink": 1,
}
)
# Create users:
group_ids = cls.env.ref("base.group_system").ids
cls.test_user_1 = cls.env["res.users"].create(
{"name": "John", "login": "test1", "groups_id": [(6, 0, group_ids)]}
)
# Create tier definitions:
cls.tier_def_obj = cls.env["tier.definition"]
cls.tier_def_obj.create(
{
"model_id": cls.tester_model.id,
"review_type": "individual",
"reviewer_id": cls.test_user_1.id,
"definition_domain": "[('test_field', '>', 1.0)]",
}
)
cls.test_record = cls.test_model.create({"test_field": 2.5})
@classmethod
def tearDownClass(cls):
cls.loader.restore_registry()
return super(TestPurchaseTierValidation, cls).tearDownClass()
def test_01_tier_definition_models(self):
"""When the user can validate all future reviews, it is not needed
to request a validation, the action can be done straight forward."""
res = self.tier_def_obj._get_tier_validation_model_names()
self.assertIn("purchase.order", res)
| 34.362319
| 2,371
|
376
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class PurchaseOrder(models.Model):
_name = "purchase.order"
_inherit = ["purchase.order", "tier.validation"]
_state_from = ["draft", "sent", "to approve"]
_state_to = ["purchase", "approved"]
_tier_validation_manual_config = False
| 28.923077
| 376
|
395
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models
class TierDefinition(models.Model):
_inherit = "tier.definition"
@api.model
def _get_tier_validation_model_names(self):
res = super(TierDefinition, self)._get_tier_validation_model_names()
res.append("purchase.order")
return res
| 28.214286
| 395
|
789
|
py
|
PYTHON
|
15.0
|
# © 2016 Chafique DELLI @ Akretion
# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
# 2020 Manuel Calero - Tecnativa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Purchase and Invoice Allowed Product",
"summary": "This module allows to select only products that can be "
"supplied by the vendor",
"version": "15.0.2.0.0",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["purchase", "base_view_inheritance_extension"],
"data": [
"views/res_partner_view.xml",
"views/account_move_views.xml",
"views/purchase_order_view.xml",
],
"installable": True,
}
| 37.47619
| 787
|
2,862
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import Form, TransactionCase
class TestPurchaseAllowedProduct(TransactionCase):
def setUp(self):
super().setUp()
self.supplierinfo_model = self.env["product.supplierinfo"]
self.product_model = self.env["product.product"]
self.partner_4 = self.env.ref("base.res_partner_4")
self.supplierinfo = self.supplierinfo_model.search(
[("name", "=", self.partner_4.id)]
)
self.partner_4_supplied_products = self.product_model.search(
[
(
"product_tmpl_id",
"in",
[x.product_tmpl_id.id for x in self.supplierinfo],
)
]
)
def test_purchase_onchange(self):
"""A user creates a purchase from the form."""
self.partner_4.use_only_supplied_product = True
with Form(
self.env["purchase.order"], view="purchase.purchase_order_form"
) as purchase_form:
purchase_form.partner_id = self.partner_4
# Ensure the use_only_supplied_product is set
self.assertEqual(
purchase_form.use_only_supplied_product,
self.partner_4.use_only_supplied_product,
)
self.assertEqual(purchase_form.use_only_supplied_product, True)
supplied_product = self.product_model.with_context(
restrict_supplier_id=purchase_form.partner_id.id,
use_only_supplied_product=purchase_form.use_only_supplied_product,
)._search([])
self.assertEqual(
set(supplied_product), set(self.partner_4_supplied_products.ids)
)
def test_invoice_onchange(self):
"""A user creates a invoice from the form."""
self.partner_4.use_only_supplied_product = True
with Form(
self.env["account.move"].with_context(default_move_type="out_invoice"),
view="account.view_move_form",
) as invoice_form:
invoice_form.partner_id = self.partner_4
# Ensure the use_only_supplied_product is set
self.assertEqual(
invoice_form.use_only_supplied_product,
self.partner_4.use_only_supplied_product,
)
self.assertEqual(invoice_form.use_only_supplied_product, True)
supplied_product = self.product_model.with_context(
restrict_supplier_id=invoice_form.partner_id.id,
use_only_supplied_product=invoice_form.use_only_supplied_product,
)._search([])
self.assertEqual(
set(supplied_product), set(self.partner_4_supplied_products.ids)
)
| 39.205479
| 2,862
|
787
|
py
|
PYTHON
|
15.0
|
# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class SuppliedProductMixin(models.AbstractModel):
_name = "supplied.product.mixin"
_description = "Mixin for documents that want to restrict products"
use_only_supplied_product = fields.Boolean(
string="Use only allowed products",
help="If checked, only the products provided by this supplier "
"will be shown.",
)
@api.onchange("partner_id")
def _onchange_partner_id_supplied_product(self):
self.use_only_supplied_product = (
self.partner_id.use_only_supplied_product
or self.partner_id.commercial_partner_id.use_only_supplied_product
)
| 35.727273
| 786
|
250
|
py
|
PYTHON
|
15.0
|
# © 2016 Chafique DELLI @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
class AccountMove(models.Model):
_inherit = ["account.move", "supplied.product.mixin"]
_name = "account.move"
| 27.666667
| 249
|
288
|
py
|
PYTHON
|
15.0
|
# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ProductSupplierinfo(models.Model):
_inherit = "product.supplierinfo"
name = fields.Many2one("res.partner", index=True)
| 28.7
| 287
|
270
|
py
|
PYTHON
|
15.0
|
# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
class PurchaseOrder(models.Model):
_inherit = ["purchase.order", "supplied.product.mixin"]
_name = "purchase.order"
| 29.888889
| 269
|
1,329
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Today Mourad EL HADJ MIMOUNE @ Akretion
# Copyright 2020 Tecnativa - Manuel Calero
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models
class ProductProduct(models.Model):
_inherit = "product.product"
@api.model
def _search(
self,
args,
offset=0,
limit=None,
order=None,
count=False,
access_rights_uid=None,
):
if self.env.context.get("use_only_supplied_product"):
restrict_supplier_id = self.env.context.get("restrict_supplier_id")
seller = (
self.env["res.partner"]
.browse(restrict_supplier_id)
.commercial_partner_id
)
supplierinfos = self.env["product.supplierinfo"].search(
[("name", "=", seller.id)]
)
args += [
"|",
("product_tmpl_id", "in", supplierinfos.product_tmpl_id.ids),
("id", "in", supplierinfos.product_id.ids),
]
return super()._search(
args,
offset=offset,
limit=limit,
order=order,
count=count,
access_rights_uid=access_rights_uid,
)
| 30.204545
| 1,329
|
569
|
py
|
PYTHON
|
15.0
|
# © 2016 Chafique DELLI @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
use_only_supplied_product = fields.Boolean(
string="Order and invoice only supplied products",
help="If checked, by default you will only be able to select products"
" that can be supplied by this supplier when creating a supplier"
" invoice or purchase for it."
" This value can be changed by invoice or purchase.",
)
| 35.5
| 568
|
507
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Purchase Order Supplierinfo Update",
"summary": "Update product supplierinfo with the last purchase price",
"version": "15.0.1.0.0",
"category": "Purchase",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["ernestotejeda"],
"license": "AGPL-3",
"depends": ["purchase"],
}
| 39
| 507
|
5,486
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from dateutil.relativedelta import relativedelta
from odoo import fields
from odoo.tests import Form, TransactionCase
class TestPurchaseOrderSupplierinfoUpdate(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.product = cls.env["product.product"].create(
{"name": "Product Test", "type": "consu"} # do not depend on stock module
)
cls.supplier = cls.env["res.partner"].create({"name": "Supplier Test"})
cls.supplierinfo = cls.env["product.supplierinfo"].create(
{
"name": cls.supplier.id,
"product_tmpl_id": cls.product.product_tmpl_id.id,
"price": 100,
}
)
cls.product_2 = cls.env["product.product"].create(
{"name": "Product Test 2", "type": "consu"}
)
cls.supplierinfo_2 = cls.env["product.supplierinfo"].create(
{
"name": cls.supplier.id,
"product_tmpl_id": cls.product_2.product_tmpl_id.id,
"price": 10,
}
)
def test_confirn_purchase_order(self):
# Create a PO, confirm it and check the supplierinfo is updated
po_form = Form(self.env["purchase.order"])
po_form.partner_id = self.supplier
with po_form.order_line.new() as po_line_form:
po_line_form.product_id = self.product
self.assertEqual(po_line_form.price_unit, 100)
po_line_form.price_unit = 150
po_line_form.taxes_id.clear()
purchase_order = po_form.save()
purchase_order.button_confirm()
self.assertEqual(self.supplierinfo.price, 150)
# Create another PO, confirm it and check the supplierinfo is updated
po_form = Form(self.env["purchase.order"])
po_form.partner_id = self.supplier
with po_form.order_line.new() as po_line_form:
po_line_form.product_id = self.product
self.assertEqual(po_line_form.price_unit, 150)
po_line_form.price_unit = 200
po_line_form.taxes_id.clear()
purchase_order = po_form.save()
purchase_order.button_confirm()
self.assertEqual(self.supplierinfo.price, 200)
def test_change_price_in_confirmed_po(self):
# Create first purchase
po_form_1 = Form(self.env["purchase.order"])
po_form_1.partner_id = self.supplier
now = fields.Datetime.now()
po_form_1.date_order = now - relativedelta(days=1)
with po_form_1.order_line.new() as po_line_form:
po_line_form.product_id = self.product
po_line_form.taxes_id.clear()
purchase_order_1 = po_form_1.save()
purchase_order_1.button_confirm()
# Create second purchase
po_form_2 = Form(self.env["purchase.order"])
po_form_2.partner_id = self.supplier
with po_form_2.order_line.new() as po_line_form:
po_line_form.product_id = self.product
po_line_form.price_unit = 200
po_line_form.taxes_id.clear()
purchase_order_2 = po_form_2.save()
purchase_order_2.button_confirm()
# Change price in second purchase
with Form(purchase_order_2) as po_form_2:
with po_form_2.order_line.edit(0) as po_line_form:
po_line_form.price_unit = 300
self.assertEqual(self.supplierinfo.price, 300)
# Change price in first purchase. This doesn't update supplierinfo
# because it isn't the last purchase of this product by this supplier
with Form(purchase_order_1) as po_form_1:
with po_form_1.order_line.edit(0) as po_line_form:
po_line_form.price_unit = 400
self.assertEqual(self.supplierinfo.price, 300)
def test_create_new_line_in_a_confirmed_po(self):
# Create first purchase
po_form_1 = Form(self.env["purchase.order"])
po_form_1.partner_id = self.supplier
with po_form_1.order_line.new() as po_line_form:
po_line_form.product_id = self.product
po_line_form.taxes_id.clear()
purchase_order_1 = po_form_1.save()
purchase_order_1.button_confirm()
# Create second purchase
po_form_2 = Form(self.env["purchase.order"])
po_form_2.partner_id = self.supplier
with po_form_2.order_line.new() as po_line_form:
po_line_form.product_id = self.product
po_line_form.price_unit = 200
po_line_form.taxes_id.clear()
purchase_order_2 = po_form_2.save()
purchase_order_2.button_confirm()
# Create a new line in the first purchase (that is already confirmed)
# with another product.
# We can not use a Form due to a modifier restriction on purchase order view
# purchase/views/purchase_views.xml#L230
purchase_order_1.write(
{
"order_line": [
(
0,
0,
{
"product_id": self.product_2.id,
"product_uom": self.product_2.uom_po_id.id,
"price_unit": 20.00,
},
)
]
}
)
self.assertEqual(self.supplierinfo_2.price, 20)
| 42.527132
| 5,486
|
2,682
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
def write(self, vals):
no_updated = self.filtered(lambda r: r.state not in ["purchase", "done"])
res = super().write(vals)
if vals.get("state", "") in ["purchase", "done"]:
no_updated.mapped("order_line").update_supplierinfo_price()
return res
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
res.update_supplierinfo_price()
return res
def write(self, vals):
res = super().write(vals)
if vals.get("price_unit"):
self.update_supplierinfo_price()
return res
def update_supplierinfo_price(self):
for line in self.filtered(
lambda r: not r.display_type and r.order_id.state in ["purchase", "done"]
):
domain = [
("partner_id", "=", line.partner_id.id),
("product_id", "=", line.product_id.id),
("date_order", ">", line.date_order),
]
if not self.env["purchase.order.line"].search(domain, limit=1):
params = {"order_id": line.order_id}
seller = line.product_id._select_seller(
partner_id=line.partner_id,
quantity=line.product_qty,
date=line.order_id.date_order and line.order_id.date_order.date(),
uom_id=line.product_uom,
params=params,
)
if seller:
line._update_supplierinfo(seller)
def _update_supplierinfo(self, seller):
self.ensure_one()
new_seller_price = self.price_unit
# convert according to the currency if necessary
if self.currency_id and self.currency_id != seller.currency_id:
new_seller_price = self.currency_id._convert(
new_seller_price,
seller.currency_id,
seller.company_id,
self.date_order or fields.Date.today(),
)
# convert according to the UoM if necessary
if self.product_uom and self.product_uom != seller.product_uom:
new_seller_price = self.product_uom._compute_price(
new_seller_price, seller.product_uom
)
# Set price
if new_seller_price != seller.price:
seller.sudo().price = new_seller_price
| 37.25
| 2,682
|
530
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Purchase Requisition Order Remaining Qty",
"version": "15.0.1.0.0",
"category": "Purchases",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["purchase_requisition"],
"installable": True,
"data": ["views/purchase_requisition_view.xml"],
"maintainers": ["victoralmau"],
}
| 37.714286
| 528
|
3,141
|
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.tests import Form, TransactionCase
class TestPurchaseRequisitionOrderRemainingQty(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.requisition_type = cls.env["purchase.requisition.type"].create(
{"name": "Test type", "quantity_copy": "remaining_qty"}
)
cls.product = cls.env["product.product"].create({"name": "Test product"})
cls.partner = cls.env["res.partner"].create({"name": "Mr Odoo"})
cls.user = cls.env.ref("base.user_admin")
def _create_purchase_requisition(self):
requisition_form = Form(self.env["purchase.requisition"])
requisition_form.type_id = self.requisition_type
requisition_form.user_id = self.user
requisition_form.vendor_id = self.partner
with requisition_form.line_ids.new() as line_form:
line_form.product_id = self.product
line_form.product_qty = 5
line_form.price_unit = 1
return requisition_form.save()
def action_purchase_requisition_to_so(self, requisition_id):
purchase_form = Form(
self.env["purchase.order"].with_context(
default_requisition_id=requisition_id
)
)
return purchase_form.save()
def test_purchase_requisition_remaining_qty(self):
requisition = self._create_purchase_requisition()
requisition_line = requisition.line_ids.filtered(
lambda x: x.product_id == self.product
)
self.assertEqual(requisition_line.proposed_qty, 0)
# New order with qty: 5. Example: product_qty: 5, proposed_qty: 0
order = self.action_purchase_requisition_to_so(requisition.id)
order.button_confirm()
order_line = order.order_line.filtered(lambda x: x.product_id == self.product)
self.assertEqual(order_line.product_qty, 5)
self.assertEqual(requisition_line.proposed_qty, 5)
# Update qty in order line need to recompute proposed_qty
order_line.product_qty = 3
self.assertEqual(requisition_line.proposed_qty, 3)
# New order with qty: 2. Example: product_qty: 5, proposed_qty: 3
order = self.action_purchase_requisition_to_so(requisition.id)
order_line = order.order_line.filtered(lambda x: x.product_id == self.product)
self.assertEqual(order_line.product_qty, 2)
self.assertEqual(requisition_line.proposed_qty, 5)
# New order without line. Example: product_qty: 5, proposed_qty: 5
order = self.action_purchase_requisition_to_so(requisition.id)
self.assertEqual(len(order.order_line), 0)
# Update product_qty in requisition line
requisition_line.product_qty = 6
# New order with qty: 1. Example: product_qty: 6, proposed_qty: 5
order = self.action_purchase_requisition_to_so(requisition.id)
order_line = order.order_line.filtered(lambda x: x.product_id == self.product)
self.assertEqual(order_line.product_qty, 1)
| 48.292308
| 3,139
|
417
|
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 import fields, models
class PurchaseRequisitionType(models.Model):
_inherit = "purchase.requisition.type"
quantity_copy = fields.Selection(
selection_add=([("remaining_qty", "Use remaining quantities of agreement")]),
ondelete={"remaining_qty": "set default"},
)
| 31.923077
| 415
|
1,403
|
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 import api, fields, models
class PurchaseRequisitionLine(models.Model):
_inherit = "purchase.requisition.line"
proposed_qty = fields.Float(compute="_compute_proposed_qty", store=True)
@api.depends(
"requisition_id.purchase_ids",
"requisition_id.purchase_ids.order_line",
"requisition_id.purchase_ids.order_line.product_id",
"requisition_id.purchase_ids.order_line.product_qty",
"requisition_id.purchase_ids.state",
)
def _compute_proposed_qty(self):
for item in self:
item.proposed_qty = sum(
item.requisition_id.purchase_ids.filtered(
lambda x: x.state not in ("cancel")
)
.order_line.filtered(lambda x: x.product_id == item.product_id)
.mapped("product_qty")
)
def _prepare_purchase_order_line(
self, name, product_qty=0.0, price_unit=0.0, taxes_ids=False
):
if self.requisition_id.is_quantity_copy == "remaining_qty":
product_qty = self.product_qty - self.proposed_qty
return super()._prepare_purchase_order_line(
name=name,
product_qty=product_qty,
price_unit=price_unit,
taxes_ids=taxes_ids,
)
| 35.923077
| 1,401
|
575
|
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 import api, models
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
@api.onchange("requisition_id")
def _onchange_requisition_id(self):
"""In this function the lines are added to the order. At the end we will
auto-delete the lines with quantity 0."""
result = super()._onchange_requisition_id()
self.order_line -= self.order_line.filtered(lambda x: x.product_qty == 0)
return result
| 35.8125
| 573
|
522
|
py
|
PYTHON
|
15.0
|
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
"name": "Purchase Product Last Price Info",
"version": "15.0.2.0.1",
"category": "Purchase Management",
"license": "AGPL-3",
"author": "AvanzOSC, Tecnativa, Odoo Community Association (OCA)",
"development_status": "Production/Stable",
"maintainers": ["LoisRForgeFlow"],
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase"],
"data": ["views/product_views.xml"],
"installable": True,
}
| 34.8
| 522
|
4,040
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 ForgeFlow S.L.
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import odoo.tests.common as common
from odoo import fields
class TestPurchaseLastPriceInfo(common.TransactionCase):
def setUp(self):
super().setUp()
self.currency_usd = self.env.ref("base.USD")
self.currency_eur = self.env.ref("base.EUR")
self.purchase_model = self.env["purchase.order"]
self.purchase_line_model = self.env["purchase.order.line"]
self.product = self.env.ref("product.consu_delivery_01")
self.partner = self.env.ref("base.res_partner_1")
# Create custom rates to USD + EUR
self._create_currency_rate(self.currency_usd, "2000-01-01", 1.0)
self._create_currency_rate(self.currency_eur, "2000-01-01", 2.0)
def _create_currency_rate(self, currency_id, name, rate):
self.env["res.currency.rate"].create(
{"currency_id": currency_id.id, "name": name, "rate": rate}
)
def test_purchase_last_price_info_demo(self):
purchase_order = self.env.ref("purchase.purchase_order_6")
purchase_order.write(
{"date_order": "2000-01-01", "currency_id": self.currency_usd.id}
)
purchase_order.button_confirm()
purchase_lines = self.purchase_line_model.search(
[
("product_id", "=", self.product.id),
("state", "in", ["purchase", "done"]),
]
).sorted(key=lambda l: l.order_id.date_order, reverse=True)
first_purchase_line = fields.first(purchase_lines)
self.assertEqual(
fields.Datetime.from_string(first_purchase_line.order_id.date_order).date(),
fields.Datetime.from_string(self.product.last_purchase_date).date(),
)
self.assertEqual(
first_purchase_line.price_unit, self.product.last_purchase_price
)
self.assertEqual(
first_purchase_line.order_id.partner_id,
self.product.last_purchase_supplier_id,
)
self.assertEqual(
first_purchase_line.currency_id, self.product.last_purchase_currency_id
)
self.assertEqual(self.product.last_purchase_currency_id, self.currency_usd)
self.assertEqual(self.product.last_purchase_price_currency, 1.0)
def test_purchase_last_price_info_new_order(self):
purchase_order = self.purchase_model.create(
{
"date_order": "2000-01-01",
"currency_id": self.currency_eur.id,
"partner_id": self.partner.id,
"order_line": [
(
0,
0,
{
"product_id": self.product.id,
"product_uom": self.product.uom_id.id,
"price_unit": self.product.standard_price,
"name": self.product.name,
"date_planned": fields.Datetime.now(),
"product_qty": 1,
},
)
],
}
)
purchase_order.button_confirm()
self.assertEqual(
fields.Datetime.from_string(purchase_order.date_order).date(),
fields.Datetime.from_string(self.product.last_purchase_date).date(),
)
first_order_line = fields.first(purchase_order.order_line)
self.assertEqual(first_order_line.price_unit, self.product.last_purchase_price)
self.assertEqual(first_order_line.price_unit, self.product.last_purchase_price)
self.assertEqual(self.product.last_purchase_currency_id, self.currency_eur)
self.assertEqual(self.product.last_purchase_price_currency, 2.0)
self.assertEqual(self.partner, self.product.last_purchase_supplier_id)
purchase_order.button_cancel()
self.assertEqual(purchase_order.state, "cancel")
| 44.373626
| 4,038
|
2,211
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# Copyright 2019 ForgeFlow S.L.
# 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 ProductTemplate(models.Model):
_inherit = "product.template"
last_purchase_line_ids = fields.One2many(
comodel_name="purchase.order.line",
related="product_variant_ids.last_purchase_line_ids",
string="Last Purchase Order Lines",
)
last_purchase_line_id = fields.Many2one(
comodel_name="purchase.order.line",
compute="_compute_last_purchase_line_id",
string="Last Purchase Line",
)
last_purchase_price = fields.Float(compute="_compute_last_purchase_line_id_info")
last_purchase_date = fields.Datetime(compute="_compute_last_purchase_line_id_info")
last_purchase_supplier_id = fields.Many2one(
comodel_name="res.partner",
compute="_compute_last_purchase_line_id_info",
string="Last Supplier",
)
last_purchase_currency_id = fields.Many2one(
comodel_name="res.currency",
compute="_compute_last_purchase_line_id_info",
string="Last Purchase Currency",
)
show_last_purchase_price_currency = fields.Boolean(
related="product_variant_ids.show_last_purchase_price_currency",
)
last_purchase_price_currency = fields.Float(
string="Last currency purchase price",
related="product_variant_ids.last_purchase_price_currency",
digits=0,
)
@api.depends("last_purchase_line_ids")
def _compute_last_purchase_line_id(self):
for item in self:
item.last_purchase_line_id = fields.first(item.last_purchase_line_ids)
@api.depends("last_purchase_line_id")
def _compute_last_purchase_line_id_info(self):
for item in self:
item.last_purchase_price = item.last_purchase_line_id.price_unit
item.last_purchase_date = item.last_purchase_line_id.date_order
item.last_purchase_supplier_id = item.last_purchase_line_id.partner_id
item.last_purchase_currency_id = item.last_purchase_line_id.currency_id
| 40.907407
| 2,209
|
3,429
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# Copyright 2019 ForgeFlow S.L.
# 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 ProductProduct(models.Model):
_inherit = "product.product"
last_purchase_line_ids = fields.One2many(
comodel_name="purchase.order.line",
inverse_name="product_id",
domain=lambda self: [
("state", "in", ["purchase", "done"]),
("company_id", "in", self.env.companies.ids),
],
string="Last Purchase Order Lines",
)
last_purchase_line_id = fields.Many2one(
comodel_name="purchase.order.line",
compute="_compute_last_purchase_line_id",
string="Last Purchase Line",
)
last_purchase_price = fields.Float(compute="_compute_last_purchase_line_id_info")
last_purchase_date = fields.Datetime(compute="_compute_last_purchase_line_id_info")
last_purchase_supplier_id = fields.Many2one(
comodel_name="res.partner",
compute="_compute_last_purchase_line_id_info",
string="Last Supplier",
)
last_purchase_currency_id = fields.Many2one(
comodel_name="res.currency",
compute="_compute_last_purchase_line_id_info",
string="Last Purchase Currency",
)
show_last_purchase_price_currency = fields.Boolean(
compute="_compute_show_last_purchase_price_currency",
)
last_purchase_price_currency = fields.Float(
string="Last currency purchase price",
compute="_compute_last_purchase_price_currency",
digits=0,
)
@api.depends("last_purchase_line_ids")
def _compute_last_purchase_line_id(self):
for item in self:
item.last_purchase_line_id = fields.first(item.last_purchase_line_ids)
@api.depends("last_purchase_line_id")
def _compute_last_purchase_line_id_info(self):
for item in self:
item.last_purchase_price = item.last_purchase_line_id.price_unit
item.last_purchase_date = item.last_purchase_line_id.date_order
item.last_purchase_supplier_id = item.last_purchase_line_id.partner_id
item.last_purchase_currency_id = item.last_purchase_line_id.currency_id
@api.depends("last_purchase_line_id", "last_purchase_currency_id")
def _compute_show_last_purchase_price_currency(self):
for item in self:
last_line = item.last_purchase_line_id
item.show_last_purchase_price_currency = (
last_line
and item.last_purchase_currency_id
and item.last_purchase_currency_id != last_line.company_id.currency_id
)
@api.depends(
"last_purchase_line_id",
"show_last_purchase_price_currency",
"last_purchase_currency_id",
"last_purchase_date",
)
def _compute_last_purchase_price_currency(self):
for item in self:
if item.show_last_purchase_price_currency:
rates = item.last_purchase_currency_id._get_rates(
item.last_purchase_line_id.company_id, item.last_purchase_date
)
item.last_purchase_price_currency = rates.get(
item.last_purchase_currency_id.id
)
else:
item.last_purchase_price_currency = 1
| 39.848837
| 3,427
|
644
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-2020 Forgeflow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from odoo import SUPERUSER_ID, api
_logger = logging.getLogger(__name__)
def post_init_hook(cr, registry):
"""Loaded after installing the module."""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
purchase_requests = env["purchase.request"].search([])
_logger.info(
"Adding the department to %d purchase requests", len(purchase_requests)
)
for purchase_request in purchase_requests:
purchase_request.onchange_requested_by()
| 33.894737
| 644
|
531
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-2020 Forgeflow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Purchase Request Department",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"version": "15.0.1.0.0",
"website": "https://github.com/OCA/purchase-workflow",
"category": "Purchase Management",
"post_init_hook": "post_init_hook",
"depends": ["hr", "purchase_request"],
"data": ["views/purchase_request_department_view.xml"],
"license": "AGPL-3",
"installable": True,
}
| 35.4
| 531
|
3,473
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-2020 Forgeflow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestPurchaseRequest(TransactionCase):
def setUp(self):
super(TestPurchaseRequest, self).setUp()
self.pr_model = self.env["purchase.request"]
self.prl_model = self.env["purchase.request.line"]
self.usr_model = self.env["res.users"]
self.dep_model = self.env["hr.department"]
self.empee_model = self.env["hr.employee"]
dept_dict = {"name": "testing department"}
self.department_test = self.dep_model.create(dept_dict)
user_dict = {
"name": "User test",
"login": "tua@example.com",
"password": "base-test-passwd",
"email": "armande.hruser@example.com",
"groups_id": [
(4, self.env.ref("purchase_request.group_purchase_request_user").id)
],
}
user_test = self.usr_model.create(user_dict)
employee_dict = {
"name": "Employee test",
"department_id": self.department_test.id,
"user_id": user_test.id,
}
self.emp_test = self.empee_model.create(employee_dict)
dept_dict2 = {"name": "testing department"}
self.department_test2 = self.dep_model.create(dept_dict2)
user_dict2 = {
"name": "User test",
"login": "tua@example2.com",
"password": "base-test-passwd",
"email": "armande.hruser@example.com",
"groups_id": [
(4, self.env.ref("purchase_request.group_purchase_request_user").id)
],
}
self.user_test2 = self.usr_model.create(user_dict2)
employee_dict2 = {
"name": "Employee test",
"department_id": self.department_test2.id,
"user_id": self.user_test2.id,
}
self.emp_test2 = self.empee_model.create(employee_dict2)
pr_dict = {
"picking_type_id": self.env.ref("stock.picking_type_in").id,
"requested_by": user_test.id,
}
self.purchase_request = self.pr_model.with_user(user_test).create(pr_dict)
prl_test = {
"request_id": self.purchase_request.id,
"product_id": self.env.ref("product.product_product_13").id,
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
"product_qty": 5.0,
}
self.purchase_request_line = self.prl_model.create(prl_test)
self.purchase_request.button_to_approve()
def test_purchase_request_department(self):
self.assertEqual(
self.purchase_request.department_id,
self.department_test,
"Invalid department found in the purchase request",
)
def test_purchase_request_line_department(self):
self.assertEqual(
self.purchase_request_line.department_id,
self.department_test,
"Invalid department found in the purchase request line",
)
def test_onchange_method(self):
self.purchase_request.button_draft()
self.purchase_request.sudo().requested_by = self.user_test2
self.purchase_request.sudo().onchange_requested_by()
self.assertEqual(
self.purchase_request.department_id,
self.department_test2,
"Invalid department found in the purchase request",
)
| 39.465909
| 3,473
|
1,064
|
py
|
PYTHON
|
15.0
|
# Copyright 2017-2020 Forgeflow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class PurchaseRequest(models.Model):
_inherit = "purchase.request"
def _get_my_department(self):
employees = self.env.user.employee_ids
return (
employees[0].department_id
if employees
else self.env["hr.department"] or False
)
department_id = fields.Many2one(
comodel_name="hr.department",
string="Department",
default=lambda self: self._get_my_department(),
)
@api.onchange("requested_by")
def onchange_requested_by(self):
employees = self.requested_by.employee_ids
self.department_id = employees[:1].department_id
class PurchaseRequestLine(models.Model):
_inherit = "purchase.request.line"
department_id = fields.Many2one(
comodel_name="hr.department",
related="request_id.department_id",
store=True,
string="Department",
readonly=True,
)
| 28
| 1,064
|
580
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Tecnativa - Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3
{
"name": "Purchase Order Line Deep Sort",
"version": "15.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Purchase Management",
"website": "https://github.com/OCA/purchase-workflow",
"summary": "Purchase Order Line Sort",
"depends": ["purchase"],
"data": ["views/res_config_settings_views.xml", "views/purchase_order_views.xml"],
"installable": True,
}
| 38.666667
| 580
|
7,638
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo.tests import common
class TestPurchaseOrderLineDeepSort(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
po_model = cls.env["purchase.order"]
cls.po_line_model = cls.env["purchase.order.line"]
cls.product_obj = cls.env["product.product"]
cls.product_1 = cls.product_obj.create(
{"name": "Test product 1", "default_code": "CDE", "standard_price": 7.5}
)
cls.product_2 = cls.product_obj.create(
{"name": "Test product 2", "default_code": "BCD", "standard_price": 7.3}
)
cls.product_3 = cls.product_obj.create(
{"name": "Test product 3", "default_code": "ABC", "standard_price": 7.4}
)
supplier = cls.env["res.partner"].create({"name": "Supplier"})
cls.po = po_model.create({"partner_id": supplier.id})
cls.po_line_1 = cls.po_line_model.create(
{
"order_id": cls.po.id,
"product_id": cls.product_1.id,
"date_planned": "2018-11-01",
"name": "Test 1",
"product_qty": 3.0,
"product_uom": cls.product_1.uom_id.id,
"price_unit": 10.0,
}
)
cls.po_line_2 = cls.po_line_model.create(
{
"order_id": cls.po.id,
"product_id": cls.product_2.id,
"date_planned": "2018-11-05",
"name": "Test 2",
"product_qty": 4.0,
"product_uom": cls.product_2.uom_id.id,
"price_unit": 6.0,
}
)
cls.po_line_3 = cls.po_line_model.create(
{
"order_id": cls.po.id,
"product_id": cls.product_3.id,
"date_planned": "2018-11-03",
"name": "Test 3",
"product_qty": 2.0,
"product_uom": cls.product_3.uom_id.id,
"price_unit": 3.0,
}
)
def _check_value(self, lines, value1, value2):
self.assertEqual(lines[0].product_id, value1)
self.assertEqual(lines[2].product_id, value2)
def test_without_line_order(self):
self.assertEqual(self.po.order_line[0].product_id, self.product_1)
self.assertEqual(self.po.order_line[2].product_id, self.product_3)
def test_line_by_name(self):
"""Test if lines are ordered by purchase line name"""
self.po.write({"line_order": "name", "line_direction": "asc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_1, self.product_3)
self.assertEqual(lines[1].name, "Test 2")
self.po.write({"line_direction": "desc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_3, self.product_1)
self.assertEqual(lines[1].name, "Test 2")
def test_line_by_product_name(self):
"""Test if lines are ordered by product name"""
self.po.write({"line_order": "product_id.name", "line_direction": "asc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_1, self.product_3)
self.assertEqual(lines[1].product_id.name, "Test product 2")
self.po.write({"line_direction": "desc"})
lines = self.po_line_model.search(
[("order_id", "=", self.po.id)], order="sequence"
)
self._check_value(lines, self.product_3, self.product_1)
self.assertEqual(lines[1].product_id.name, "Test product 2")
def test_line_by_product_code(self):
"""Test if lines are ordered by product code"""
self.po.write(
{"line_order": "product_id.default_code", "line_direction": "asc"}
)
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_3, self.product_1)
self.assertEqual(lines[1].product_id.default_code, "BCD")
self.po.write({"line_direction": "desc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_1, self.product_3)
self.assertEqual(lines[1].product_id.default_code, "BCD")
def test_line_by_date_planned(self):
"""Test if lines are ordered by purchase line date planned"""
self.po.write({"line_order": "date_planned", "line_direction": "asc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_1, self.product_2)
self.assertEqual(fields.Date.to_string(lines[1].date_planned), "2018-11-03")
self.po.write({"line_direction": "desc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_2, self.product_1)
self.assertEqual(fields.Date.to_string(lines[1].date_planned), "2018-11-03")
def test_line_by_price_unit(self):
"""Test if lines are ordered by purchase line price"""
self.po.write({"line_order": "price_unit", "line_direction": "asc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_3, self.product_1)
self.assertAlmostEqual(lines[1].price_unit, 6.0)
self.po.write({"line_direction": "desc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_1, self.product_3)
self.assertAlmostEqual(lines[1].price_unit, 6.0)
def test_line_by_product_qty(self):
"""Test if lines are ordered by purchase line product_qty"""
self.po.write({"line_order": "product_qty", "line_direction": "asc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_3, self.product_2)
self.assertAlmostEqual(lines[1].product_qty, 3.0)
self.po.write({"line_direction": "desc"})
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self._check_value(lines, self.product_2, self.product_3)
self.assertAlmostEqual(lines[1].product_qty, 3.0)
def test_product_sort_false_values(self):
"""
Test purchase order lines sorted lines with False values and
string values (default_code).
Test sort lines with numeric values with False values
"""
self.product_2.default_code = False
self.po.write(
{"line_order": "product_id.default_code", "line_direction": "asc"}
)
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self.assertEqual(lines[0].product_id, self.product_2)
self.po.write({"line_order": "price_unit", "line_direction": "asc"})
self.po_line_3.price_unit = 0.0
lines = self.po_line_model.search([("order_id", "=", self.po.id)])
self.assertEqual(lines[0], self.po_line_3)
def test_res_config_settings(self):
purchase_config = (
self.env["res.config.settings"]
.sudo()
.create(
{"po_line_order_default": "name", "po_line_direction_default": "asc"}
)
)
purchase_config.po_line_order_default = False
purchase_config.onchange_po_line_order_default()
self.assertFalse(purchase_config.po_line_direction_default)
| 46.290909
| 7,638
|
2,490
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Tecnativa - Vicent Cubells <vicent.cubells@tecnativa.com>
# Copyright 2019 Tecnativa - Pedro M. Baeza
# Copyright 2019 Tecnativa - Sergio Teruel
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3
from odoo import api, fields, models
from .res_company import SORTING_CRITERIA, SORTING_DIRECTION
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
line_order = fields.Selection(
selection=SORTING_CRITERIA,
string="Sort Lines By",
default=lambda self: self.env.user.company_id.default_po_line_order,
)
line_direction = fields.Selection(
selection=SORTING_DIRECTION,
string="Sort Direction",
default=lambda self: self.env.user.company_id.default_po_line_direction,
)
@api.onchange("line_order")
def onchange_line_order(self):
if not self.line_order:
self.line_direction = False
def _sort_purchase_line(self):
def resolve_subfields(obj, line_order):
subfields = line_order.split(".")
res = obj
str_fields = ("text", "varchar", "timestamp", "date")
for subfield in subfields:
if res._fields[subfield].column_type[0] in str_fields:
res = getattr(res, subfield) or ""
else:
res = getattr(res, subfield)
return res
if not self.line_order and not self.line_direction:
return
reverse = self.line_direction == "desc"
sequence = 0
sorted_lines = self.order_line.sorted(
key=lambda p: resolve_subfields(p, self.line_order),
reverse=reverse,
)
for line in sorted_lines:
sequence += 10
if line.sequence == sequence:
continue
line.sequence = sequence
def write(self, values):
res = super().write(values)
if (
"order_line" in values
or "line_order" in values
or "line_direction" in values
):
self._sort_purchase_line()
return res
@api.model
def create(self, values):
purchase = super().create(values)
purchase._sort_purchase_line()
return purchase
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
@api.model
def create(self, vals):
line = super().create(vals)
line.order_id._sort_purchase_line()
return line
| 31.125
| 2,490
|
953
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Tecnativa - Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3
from odoo import fields, models
SORTING_CRITERIA = [
("name", "By name"),
("product_id.name", "By product name"),
("product_id.default_code", "By product reference"),
("date_planned", "By date planned"),
("price_unit", "By unit price"),
("product_qty", "By quantity"),
]
SORTING_DIRECTION = [
("asc", "Ascending"),
("desc", "Descending"),
]
class ResCompany(models.Model):
_inherit = "res.company"
default_po_line_order = fields.Selection(
selection=SORTING_CRITERIA,
string="Line Order",
help="Select a sorting criteria for purchase order lines.",
)
default_po_line_direction = fields.Selection(
selection=SORTING_DIRECTION,
string="Sort Direction",
help="Select a sorting direction for purchase order lines.",
)
| 28.878788
| 953
|
845
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Tecnativa - Vicent Cubells <vicent.cubells@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3
from odoo import api, fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
po_line_order_default = fields.Selection(
related="company_id.default_po_line_order",
string="Line Order",
readonly=False,
)
po_line_direction_default = fields.Selection(
related="company_id.default_po_line_direction",
string="Sort Direction",
readonly=False,
)
@api.onchange("po_line_order_default")
def onchange_po_line_order_default(self):
"""Reset direction line order when user remove order field value"""
if not self.po_line_order_default:
self.po_line_direction_default = False
| 33.8
| 845
|
691
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 David Vidal <david.vidal@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Purchase Order Product Recommendation Secondary Unit",
"summary": "Add secondary unit to recommend products wizard",
"version": "15.0.1.0.0",
"category": "Purchases",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"purchase_order_product_recommendation",
"purchase_order_secondary_unit",
],
"data": ["wizards/purchase_order_recommendation_view.xml"],
}
| 38.388889
| 691
|
2,460
|
py
|
PYTHON
|
15.0
|
# Copyright 2023 Tecnativa - Pilar Vargas
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import Form, TransactionCase, tagged
@tagged("-at_install", "post_install")
class TestPurchaseOrderProductRecommendationSecondaryUnit(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Active multiple units of measure security group for user
cls.env.user.groups_id = [(4, cls.env.ref("uom.group_uom").id)]
cls.partner = cls.env["res.partner"].create({"name": "Partner"})
cls.product = cls._create_product_with_secondary_unit(cls)
cls.product.purchase_secondary_uom_id = cls.product.secondary_uom_ids
cls.purchase_order = cls._create_purchase_order(cls)
cls.purchase_order.button_confirm()
# Create a purchase order for the same customer
cls.new_po = cls.env["purchase.order"].create({"partner_id": cls.partner.id})
def _create_product_with_secondary_unit(self):
product = Form(self.env["product.product"])
product.name = "Test product"
product.detailed_type = "product"
product.uom_id = self.env.ref("uom.product_uom_kgm")
product.uom_po_id = self.env.ref("uom.product_uom_kgm")
with product.secondary_uom_ids.new() as line:
line.code = "PQ1-5"
line.name = "Package of"
line.uom_id = self.env.ref("uom.product_uom_kgm")
line.factor = 1.5
return product.save()
def _create_purchase_order(self):
order_form = Form(self.env["purchase.order"])
order_form.partner_id = self.partner
with order_form.order_line.new() as line_form:
line_form.product_id = self.product
line_form.product_qty = 10
line_form.price_unit = 100.00
return order_form.save()
def wizard(self):
"""Get a wizard."""
wizard = (
self.env["purchase.order.recommendation"]
.with_context(active_id=self.new_po.id, active_model="purchase.order")
.create({})
)
wizard._generate_recommendations()
return wizard
def test_recommendation_secondary_unit(self):
wizard = self.wizard()
wizard.show_all_partner_products = True
wizard._generate_recommendations()
self.assertEqual(
wizard.line_ids.secondary_uom_id, self.product.secondary_uom_ids
)
| 41.694915
| 2,460
|
3,725
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 David Vidal <david.vidal@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from math import ceil
from odoo import api, fields, models
from odoo.tools.float_utils import float_compare, float_round
class PurchaseOrderRecommendation(models.TransientModel):
_inherit = "purchase.order.recommendation"
@api.model
def _prepare_wizard_line(self, vals, order_line=False):
res = super()._prepare_wizard_line(vals, order_line)
secondary_uom_id = (
order_line
and order_line.secondary_uom_id
or vals.get("product_id")
and vals["product_id"].purchase_secondary_uom_id
)
secondary_uom_qty = False
if not order_line and secondary_uom_id:
secondary_uom_qty = ceil(
res.get("units_included", 0) / secondary_uom_id.factor
)
res["units_included"] = secondary_uom_qty * secondary_uom_id.factor
res.update(
{
"secondary_uom_id": secondary_uom_id and secondary_uom_id.id,
"secondary_uom_qty": (
order_line and order_line.secondary_uom_qty or secondary_uom_qty
),
}
)
return res
class PurchaseOrderRecommendationLine(models.TransientModel):
_inherit = "purchase.order.recommendation.line"
secondary_uom_id = fields.Many2one(
comodel_name="product.secondary.unit",
related="product_id.purchase_secondary_uom_id",
readonly=True,
)
secondary_uom_qty = fields.Float(
string="Secondary Qty",
digits="Product Unit of Measure",
)
@api.onchange("secondary_uom_id", "secondary_uom_qty")
def _onchange_secondary_uom(self):
if not self.secondary_uom_id:
return
factor = self.secondary_uom_id.factor * self.product_id.uom_id.factor
qty = float_round(
self.secondary_uom_qty * factor,
precision_rounding=self.product_id.uom_id.rounding,
)
if (
float_compare(
self.units_included,
qty,
precision_rounding=self.product_id.uom_id.rounding,
)
!= 0
):
self.units_included = qty
@api.onchange("units_included")
def _onchange_units_included_purchase_order_secondary_unit(self):
if not self.secondary_uom_id:
return
factor = self.secondary_uom_id.factor * self.product_id.uom_id.factor
qty = float_round(
self.units_included / (factor or 1.0),
precision_rounding=self.secondary_uom_id.uom_id.rounding,
)
if (
float_compare(
self.secondary_uom_qty,
qty,
precision_rounding=self.secondary_uom_id.uom_id.rounding,
)
!= 0
):
self.secondary_uom_qty = qty
def _prepare_update_po_line(self):
res = super()._prepare_update_po_line()
if self.secondary_uom_id and self.secondary_uom_qty:
res.update(
{
"secondary_uom_id": self.secondary_uom_id.id,
"secondary_uom_qty": self.secondary_uom_qty,
}
)
return res
def _prepare_new_po_line(self, sequence):
res = super()._prepare_new_po_line(sequence)
if self.secondary_uom_id and self.secondary_uom_qty:
res.update(
{
"secondary_uom_id": self.secondary_uom_id.id,
"secondary_uom_qty": self.secondary_uom_qty,
}
)
return res
| 33.863636
| 3,725
|
622
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Purchase Order Product Recommendation Forecast",
"summary": "Obtain linear progression forecast from reference years",
"version": "15.0.1.0.0",
"category": "Purchases",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["purchase_order_product_recommendation"],
"data": ["wizards/purchase_order_recommendation_view.xml"],
}
| 41.466667
| 622
|
5,100
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo.addons.purchase_order_product_recommendation.tests import test_recommendation
class TestSaleProductClassification(test_recommendation.RecommendationCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Quickly generate 3 products with a different price each. We'll be
# using a new set of products to avoid history pollution.
cls.forecasted_products = cls.env["product.product"].create(
[
{
"name": "Test product forecast {}".format(i + 4),
"type": "product",
"seller_ids": [(0, 0, {"name": cls.partner.id})],
}
for i in range(3)
]
)
cls.prod_4, cls.prod_5, cls.prod_6 = cls.forecasted_products
# History of deliveries we want to reproduce separeted for the periods
# we'll evaluate.
# - Period X is the one we set in the wizard
# - Period A and B are those computed from the year of reference
# Let's create the move lines according to this history
history_data = {
# Period A (p4, p5, p6)
"2019-03-05": (5, 18, 520),
"2019-03-10": (6, 1, 436),
"2019-03-20": (6, 0, 654),
# Period B next(A) (p4, p5, p6)
"2019-04-05": (18, 0, 40),
"2019-04-10": (20, 0, 65),
"2019-04-20": (15, 19, 68),
# Period X (p4, p5, p6)
"2021-03-05": (3, 10, 215),
"2021-03-10": (2, 0, 158),
"2021-03-20": (5, 2, 120),
}
cls.sml_forecast = cls.env["stock.move.line"]
for history_date, history_tuple in history_data.items():
history_date = fields.Datetime.from_string(history_date)
cls.sml_forecast |= cls.env["stock.move.line"].create(
[
{
"date": history_date,
"product_id": product.id,
"product_uom_id": product.uom_id.id,
"qty_done": qty,
"location_id": cls.wh1.lot_stock_id.id,
"location_dest_id": cls.customer_loc.id,
"company_id": cls.env.company.id,
}
for product, qty in zip(cls.forecasted_products, history_tuple)
if qty
]
)
# Ensure that the state is set
cls.sml_forecast.write({"state": "done"})
# Initializa current stock:
# p4 | p5 | p6
# 15 | 10 | 200
cls.env["stock.quant"].create(
[
{
"product_id": product.id,
"location_id": cls.wh1.lot_stock_id.id,
"quantity": qty,
}
for product, qty in zip(cls.forecasted_products, (15, 10, 200))
]
)
def test_recommendation_forecast(self):
"""Test forecast for different products and slices of time"""
# We'll be choosing period X for the wizard
wizard = self.wizard()
wizard.date_begin = "2021-03-01"
wizard.date_end = "2021-03-31"
wizard.year_of_reference = "2019"
wizard._generate_recommendations()
# The table of truth for the increments should be:
# p4 | p5 | p6
# ---------|-------|---------
# 211,76% | 0,00% | -89,25%
line_p4 = wizard.line_ids.filtered(
lambda x: x.product_id == self.forecasted_products[0]
)
line_p5 = wizard.line_ids.filtered(
lambda x: x.product_id == self.forecasted_products[1]
)
line_p6 = wizard.line_ids.filtered(
lambda x: x.product_id == self.forecasted_products[2]
)
self.assertAlmostEqual(line_p4.forecasted_increment, 2.1176, 4)
self.assertAlmostEqual(line_p5.forecasted_increment, 0)
self.assertAlmostEqual(line_p6.forecasted_increment, -0.8925, 4)
# The table of truth for the reccomended quantities according to the
# current stock should be this:
# p | rec | % | fcst | rec %
# p4 | 0 | 211,76% | 31,18 | 16,18 -> expected increment
# p5 | 2 | 0,00% | 12 | 2 -> no change expected
# p6 | 293 | -89,25% | 52,97 | 0 -> sales will drop; don't ressuply
# rec: normal recommendation
# fcst: units that we expect to deliver
# rec %: recommendation according to forecast and current stock
self.assertAlmostEqual(line_p4.units_forecasted, 31.18, 2)
self.assertAlmostEqual(line_p4.units_included, 16.18, 2)
self.assertAlmostEqual(line_p5.units_forecasted, 12)
self.assertAlmostEqual(line_p5.units_included, 2)
self.assertAlmostEqual(line_p6.units_forecasted, 52.97, 2)
self.assertAlmostEqual(line_p6.units_included, 0)
| 43.965517
| 5,100
|
6,558
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from dateutil.relativedelta import relativedelta
from odoo import _, api, fields, models
class PurchaseOrderRecommendation(models.TransientModel):
_inherit = "purchase.order.recommendation"
@api.model
def _default_year_of_reference(self):
if len(self._selection_year_of_reference()) > 1:
return str(fields.Date.today().year - 1)
return str(fields.Date.today().year)
year_of_reference = fields.Selection(
string="Year of reference",
selection="_selection_year_of_reference",
default=_default_year_of_reference,
)
@api.model
def _selection_year_of_reference(self):
"""A selection of years from the first delivery"""
year = fields.Date.today().year
first_year = self.env["stock.move.line"].search_read(
[("location_dest_id.usage", "=", "customer"), ("state", "=", "done")],
["date"],
order="date ASC",
limit=1,
)
first_year = first_year and first_year[0].get("date").year or year
return [(str(x), str(x)) for x in range(year, first_year - 1, -1)]
@api.onchange("year_of_reference")
def _generate_year_of_reference_recommendations(self):
"""Trigger the general onchange method"""
return super()._generate_recommendations()
def _get_year_of_reference_period(self):
"""We'll compute the deliveries for this period"""
year_diff_begin = self.date_begin.year - int(self.year_of_reference)
year_diff_end = self.date_end.year - int(self.year_of_reference)
year_of_reference_begin = self.date_begin - relativedelta(years=year_diff_begin)
year_of_reference_end = self.date_end - relativedelta(years=year_diff_end)
return year_of_reference_begin, year_of_reference_end
def _get_reference_next_period(self):
"""We'll also compute them for this other period so we can get the
expected increment"""
date_begin, date_end = self._get_year_of_reference_period()
range_days = (date_end - date_begin).days
next_period_begin = date_end + relativedelta(days=1)
next_period_end = date_end + relativedelta(days=range_days + 1)
return next_period_begin, next_period_end
def _find_move_line(self, src="internal", dst="customer"):
"""Use the year of reference to compute the expected increment for
a given period. This way, we put a period in the wizard and then
we compute how it performed in relation to next period. This way
we can draw a simple forecast expecting a linear progression of
the product deliveries"""
found_lines = super()._find_move_line(src, dst)
if (
dst != "customer"
or not self.year_of_reference
or int(self.year_of_reference) == self.date_begin.year
or self.env.context.get("period_date_begin")
):
return found_lines
# The period for the year of reference
(
year_of_reference_begin,
year_of_reference_end,
) = self._get_year_of_reference_period()
# The next period in the same year
(
year_of_reference_next_begin,
year_of_reference_next_end,
) = self._get_reference_next_period()
# Now we gather the move lines for such periods and compute the
# increments which we'll attach to the final dict
year_ref_found_lines = self.with_context(
period_date_begin=year_of_reference_begin,
period_date_end=year_of_reference_end,
)._find_move_line(src, dst)
year_ref_next_period_found_lines = self.with_context(
period_date_begin=year_of_reference_next_begin,
period_date_end=year_of_reference_next_end,
)._find_move_line(src, dst)
for product_id, found_line in found_lines.items():
qty_ref_done = year_ref_found_lines.get(product_id, {}).get("qty_done", 0)
qty_ref_next_done = year_ref_next_period_found_lines.get(
product_id, {}
).get("qty_done", 0)
# We won't consider as we can't rely on the info if there's no data
# What if the product didn't exist prior to the next period?
if not qty_ref_done:
continue
increment = qty_ref_next_done / qty_ref_done - 1
found_line.update({"forecasted_increment": increment})
return found_lines
def _prepare_wizard_line(self, vals, order_line=False):
res = super()._prepare_wizard_line(vals, order_line)
# What if no qty has been done in the reference period?
increment = vals.get("forecasted_increment", 0)
units_forecasted = vals.get("qty_delivered", 0) * (1 + increment)
units_virtual_available = res.get("units_virtual_available", 0)
res.update(
{"forecasted_increment": increment, "units_forecasted": units_forecasted}
)
# Force the recommended qty to the forcasted one
if (
increment
and self.year_of_reference
and int(self.year_of_reference) != self.date_begin.year
):
qty_to_order = abs(min(0, units_virtual_available - units_forecasted))
res.update(
{
"is_modified": bool(qty_to_order),
"units_included": (
order_line and order_line.product_qty or qty_to_order
),
}
)
return res
class PurchaseOrderRecommendationLine(models.TransientModel):
_inherit = "purchase.order.recommendation.line"
forecasted_increment = fields.Float(
readonly=True,
)
forecasted_increment_text = fields.Char(
string="% inc.",
compute="_compute_forecasted_increment_text",
readonly=True,
)
units_forecasted = fields.Float(
string="Qty recommended",
readonly=True,
)
@api.depends("forecasted_increment")
def _compute_forecasted_increment_text(self):
"""Human friendly forecasted increment"""
for line in self:
if not line.forecasted_increment:
line.forecasted_increment_text = _(" n/a ")
continue
line.forecasted_increment_text = "{:.2f}".format(
line.forecasted_increment * 100
)
| 41.770701
| 6,558
|
639
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Purchase Order Approved",
"summary": "Add a new state 'Approved' in purchase orders.",
"version": "15.0.1.0.0",
"category": "Purchases",
"website": "https://github.com/OCA/purchase-workflow",
"author": "ForgeFlow, ACSONE SA/NV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["purchase_stock"],
"data": [
"views/res_partner.xml",
"views/purchase_order_view.xml",
"views/res_config_view.xml",
],
}
| 33.631579
| 639
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.