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
|
---|---|---|---|---|---|---|
4,937 |
py
|
PYTHON
|
15.0
|
# Copyright 2019 Tecnativa - Vicent Cubells
# Copyright 2022 Tecnativa - Víctor Martínez
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.tests.common import TransactionCase
class TestDeliveryFreeFeeRemoval(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
product = cls.env["product.product"].create(
{"name": "Product", "detailed_type": "product"}
)
product_delivery = cls.env["product.product"].create(
{
"name": "Delivery Product",
"detailed_type": "service",
"invoice_policy": "delivery",
}
)
cls.delivery = cls.env["delivery.carrier"].create(
{
"name": "Test Delivery",
"delivery_type": "fixed",
"fixed_price": 10,
"free_over": True,
"product_id": product_delivery.id,
}
)
partner = cls.env["res.partner"].create({"name": "Test Partner"})
cls.sale = cls.env["sale.order"].create(
{
"partner_id": partner.id,
"order_line": [
(
0,
0,
{
"product_id": product.id,
"product_uom_qty": 1,
"product_uom": product.uom_id.id,
"price_unit": 3.0,
},
)
],
}
)
cls.report_obj = cls.env["ir.actions.report"]
def test_delivery_free_fee_removal_with_fee(self):
self.delivery.product_id.write({"invoice_policy": "order"})
self.sale.set_delivery_line(self.delivery, 100)
delivery_line = self.sale.mapped("order_line").filtered(lambda x: x.is_delivery)
self.assertFalse(delivery_line.is_free_delivery)
self.sale.action_confirm()
self.assertRecordValues(
delivery_line,
[
{
"is_free_delivery": False,
"qty_to_invoice": 1,
"invoice_status": "to invoice",
}
],
)
res = self.report_obj._get_report_from_name(
"sale.report_saleorder"
)._render_qweb_text(self.sale.ids, False)
self.assertRegex(str(res[0]), "Test Delivery")
def test_delivery_free_fee_removal_with_fee_invoice_policy_delivery(self):
self.sale.set_delivery_line(self.delivery, 100)
delivery_line = self.sale.mapped("order_line").filtered(lambda x: x.is_delivery)
self.assertFalse(delivery_line.is_free_delivery)
self.sale.action_confirm()
self.assertRecordValues(
delivery_line,
[
{
"is_free_delivery": False,
"qty_to_invoice": 0,
# SO not yet delivered so nothing to invoice
"invoice_status": "no",
}
],
)
res = self.report_obj._get_report_from_name(
"sale.report_saleorder"
)._render_qweb_text(self.sale.ids, False)
self.assertRegex(str(res[0]), "Test Delivery")
def test_delivery_free_fee_removal_free_fee(self):
self.sale.set_delivery_line(self.delivery, 0)
delivery_line = self.sale.mapped("order_line").filtered(lambda x: x.is_delivery)
self.assertTrue(delivery_line.is_free_delivery)
self.sale.action_confirm()
self.assertRecordValues(
delivery_line,
[
{
"is_free_delivery": True,
"qty_to_invoice": 0,
"invoice_status": "invoiced",
}
],
)
res = self.report_obj._get_report_from_name(
"sale.report_saleorder"
)._render_qweb_text(self.sale.ids, False)
self.assertNotRegex(str(res[0]), "Test Delivery")
def test_delivery_free_fee_removal_free_fee_invoice_policy_order(self):
self.delivery.product_id.write({"invoice_policy": "order"})
self.sale.set_delivery_line(self.delivery, 0)
delivery_line = self.sale.mapped("order_line").filtered(lambda x: x.is_delivery)
self.assertTrue(delivery_line.is_free_delivery)
self.sale.action_confirm()
self.assertRecordValues(
delivery_line,
[
{
"is_free_delivery": True,
"qty_to_invoice": 0,
"invoice_status": "invoiced",
}
],
)
res = self.report_obj._get_report_from_name(
"sale.report_saleorder"
)._render_qweb_text(self.sale.ids, False)
self.assertNotRegex(str(res[0]), "Test Delivery")
| 37.386364 | 4,935 |
644 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
class SaleOrder(models.Model):
_inherit = "sale.order"
def action_confirm(self):
res = super().action_confirm()
# Invoice all the free delivery line on order confirmation
# Or the order will never be fully invoiced.
delivery_lines = self.order_line.filtered(
lambda line: line.order_id.state == "sale" and line.is_free_delivery
)
for line in delivery_lines:
line.qty_delivered = line.qty_invoiced = line.product_uom_qty
return res
| 33.894737 | 644 |
553 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
is_free_delivery = fields.Boolean(compute="_compute_is_free_delivery", store=True)
@api.depends("is_delivery", "currency_id", "price_total")
def _compute_is_free_delivery(self):
for line in self:
line.is_free_delivery = line.is_delivery and line.currency_id.is_zero(
line.price_total
)
| 32.529412 | 553 |
607 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Delivery Carrier Info",
"summary": "Add code and description on carrier",
"version": "15.0.1.0.1",
"category": "Delivery",
"website": "https://github.com/OCA/delivery-carrier",
"author": "Akretion,Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": [
"delivery",
],
"data": ["views/delivery_view.xml"],
"application": False,
"installable": True,
}
| 30.3 | 606 |
379 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 Akretion (https://www.akretion.com).
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class DeliveryCarrier(models.Model):
_inherit = "delivery.carrier"
code = fields.Char(
help="Delivery Method Code (according to carrier)",
)
description = fields.Text()
| 27.071429 | 379 |
500 |
py
|
PYTHON
|
15.0
|
# © 2020 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Make Delivery Text Properties Translatable",
"category": "Hidden",
"summary": """name and website_description field of delivery carrier setup translatable.""",
"version": "15.0.1.0.0",
"depends": [
"delivery",
],
"license": "AGPL-3",
"author": "initOS, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/delivery-carrier",
}
| 33.266667 | 499 |
261 |
py
|
PYTHON
|
15.0
|
# © 2022 Thomas Rehn (initOS GmbH)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class DeliveryCarrier(models.Model):
_inherit = "delivery.carrier"
name = fields.Char(required=True, translate=True)
| 26 | 260 |
646 |
py
|
PYTHON
|
15.0
|
# Copyright 2016-2019 Tecnativa - Pedro M. Baeza
# Copyright 2017 Tecnativa - Luis M. Ontalba
# Copyright 2021 Gianmarco Conte <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Multiple destinations for the same delivery method",
"version": "15.0.1.0.2",
"category": "Delivery",
"website": "https://github.com/OCA/delivery-carrier",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["delivery"],
"demo": ["demo/delivery_carrier_demo.xml"],
"data": ["views/delivery_carrier_view.xml"],
}
| 38 | 646 |
7,294 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 Tecnativa - Luis M. Ontalba
# Copyright 2019-2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests import Form, common
class TestDeliveryMultiDestination(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.country_1 = cls.env["res.country"].create({"name": "Test country 1"})
cls.pricelist = cls.env["product.pricelist"].create(
{"name": "Test pricelist", "currency_id": cls.env.company.currency_id.id}
)
cls.partner_1 = cls.env["res.partner"].create(
{
"name": "Test partner 1",
"country_id": cls.country_1.id,
"property_product_pricelist": cls.pricelist.id,
}
)
cls.country_2 = cls.env["res.country"].create({"name": "Test country 2"})
cls.state = cls.env["res.country.state"].create(
{"name": "Test state", "code": "TS", "country_id": cls.country_2.id}
)
cls.partner_2 = cls.env["res.partner"].create(
{
"name": "Test partner 2",
"country_id": cls.country_2.id,
"state_id": cls.state.id,
"zip": "22222",
}
)
cls.partner_3 = cls.env["res.partner"].create(
{
"name": "Test partner 3",
"country_id": cls.country_2.id,
"state_id": cls.state.id,
"zip": "33333",
}
)
cls.product = cls.env["product.product"].create(
{"name": "Test carrier multi", "detailed_type": "service"}
)
cls.product_child_1 = cls.env["product.product"].create(
{"name": "Test child 1", "detailed_type": "service"}
)
cls.product_child_2 = cls.env["product.product"].create(
{"name": "Test child 2", "detailed_type": "service"}
)
cls.carrier_multi = cls._create_carrier(
cls,
(
{
"name": "Test child 1",
"product_id": cls.product_child_1,
"zip_from": 20000,
"zip_to": 29999,
"fixed_price": 50,
},
{
"name": "Test child 2",
"product_id": cls.product_child_2,
"zip_from": 30000,
"zip_to": 39999,
"fixed_price": 150,
},
),
)
cls.carrier_single = cls.carrier_multi.copy(
{
"name": "Test carrier single",
"destination_type": "one",
"child_ids": False,
}
)
cls.product = cls.env["product.product"].create(
{"name": "Test product", "detailed_type": "product", "list_price": 1}
)
cls.sale_order = cls._create_sale_order(cls)
def _create_carrier(self, childs):
carrier_form = Form(self.env["delivery.carrier"])
carrier_form.name = "Test carrier multi"
carrier_form.product_id = self.product
carrier_form.destination_type = "multi"
carrier_form.delivery_type = "fixed"
carrier_form.fixed_price = 100
for child_item in childs:
with carrier_form.child_ids.new() as child_form:
child_form.name = child_item["name"]
child_form.product_id = child_item["product_id"]
child_form.country_ids.add(self.country_2)
child_form.state_ids.add(self.state)
child_form.zip_from = child_item["zip_from"]
child_form.zip_to = child_item["zip_to"]
child_form.delivery_type = "fixed"
child_form.fixed_price = child_item["fixed_price"]
return carrier_form.save()
def _create_sale_order(self):
order_form = Form(self.env["sale.order"])
order_form.partner_id = self.partner_1
with order_form.order_line.new() as line_form:
line_form.product_id = self.product
return order_form.save()
def _choose_delivery_carrier(self, order, carrier):
wizard = Form(
self.env["choose.delivery.carrier"].with_context(
**{
"default_order_id": order.id,
"default_carrier_id": carrier.id,
}
)
)
choose_delivery_carrier = wizard.save()
choose_delivery_carrier.button_confirm()
def test_delivery_multi_destination(self):
order = self.sale_order
order.carrier_id = self.carrier_single.id
self._choose_delivery_carrier(order, order.carrier_id)
sale_order_line = order.order_line.filtered("is_delivery")
self.assertAlmostEqual(sale_order_line.price_unit, 100, 2)
self.assertTrue(sale_order_line.is_delivery)
order.carrier_id = self.carrier_multi.id
order.partner_shipping_id = self.partner_2.id
self._choose_delivery_carrier(order, order.carrier_id)
sale_order_line = order.order_line.filtered("is_delivery")
self.assertAlmostEqual(sale_order_line.price_unit, 50, 2)
self.assertTrue(sale_order_line.is_delivery)
order.partner_shipping_id = self.partner_3.id
self._choose_delivery_carrier(order, order.carrier_id)
sale_order_line = order.order_line.filtered("is_delivery")
self.assertAlmostEqual(sale_order_line.price_unit, 150, 2)
def test_search(self):
carriers = self.env["delivery.carrier"].search([])
children_carrier = self.carrier_multi.with_context(
show_children_carriers=True,
).child_ids[0]
self.assertNotIn(children_carrier, carriers)
def test_name_search(self):
carrier_names = self.env["delivery.carrier"].name_search()
children_carrier = self.carrier_multi.with_context(
show_children_carriers=True,
).child_ids[0]
self.assertTrue(all(x[0] != children_carrier.id for x in carrier_names))
def test_available_carriers(self):
self.assertEqual(
self.carrier_multi.available_carriers(self.partner_2),
self.carrier_multi,
)
def test_picking_validation(self):
"""Test a complete sales flow with picking."""
self.sale_order.carrier_id = self.carrier_multi.id
self.sale_order.partner_shipping_id = self.partner_2.id
self.sale_order.action_confirm()
picking = self.sale_order.picking_ids
self.assertEqual(picking.carrier_id, self.carrier_multi)
picking.move_lines.quantity_done = 1
picking._action_done()
self.assertAlmostEqual(picking.carrier_price, 50)
def test_delivery_carrier_multi_form(self):
carrier_form = Form(self.env["delivery.carrier"])
carrier_form.name = "Multi carrier"
carrier_form.destination_type = "multi"
with carrier_form.child_ids.new() as child_form:
child_form.name = "Child carrier"
child_form.product_id = self.product_child_1
carrier = carrier_form.save()
self.assertEqual(carrier.product_id, self.product_child_1)
| 40.977528 | 7,294 |
5,097 |
py
|
PYTHON
|
15.0
|
# Copyright 2016-2020 Tecnativa - Pedro M. Baeza
# Copyright 2017 Tecnativa - Luis M. Ontalba
# Copyright 2021 Gianmarco Conte <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class DeliveryCarrier(models.Model):
_inherit = "delivery.carrier"
child_ids = fields.One2many(
comodel_name="delivery.carrier",
inverse_name="parent_id",
string="Destination grid",
)
parent_id = fields.Many2one(
comodel_name="delivery.carrier",
string="Parent carrier",
ondelete="cascade",
)
destination_type = fields.Selection(
selection=[("one", "One destination"), ("multi", "Multiple destinations")],
default="one",
required=True,
)
@api.onchange("destination_type", "child_ids")
def _onchange_destination_type(self):
"""Define the corresponding value to avoid creation error with UX."""
if self.destination_type == "multi" and self.child_ids and not self.product_id:
self.product_id = fields.first(self.child_ids.product_id)
def search(self, args, offset=0, limit=None, order=None, count=False):
"""Don't show by default children carriers."""
if not self.env.context.get("show_children_carriers"):
if args is None:
args = []
args += [("parent_id", "=", False)]
return super(DeliveryCarrier, self).search(
args,
offset=offset,
limit=limit,
order=order,
count=count,
)
@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
"""Don't show by default children carriers."""
domain = [("parent_id", "=", False)]
return self.search(domain, limit=limit).name_get()
def available_carriers(self, partner):
"""If the carrier is multi, we test the availability on children."""
available = self.env["delivery.carrier"]
for carrier in self:
if carrier.destination_type == "one":
candidates = carrier
else:
carrier = carrier.with_context(show_children_carriers=True)
candidates = carrier.child_ids
if super(DeliveryCarrier, candidates).available_carriers(partner):
available |= carrier
return available
def rate_shipment(self, order):
"""We have to override this method for getting the proper price
according destination on sales orders.
"""
if self.destination_type == "one":
return super().rate_shipment(order)
else:
carrier = self.with_context(show_children_carriers=True)
for subcarrier in carrier.child_ids:
if subcarrier._match_address(order.partner_shipping_id):
return super(
DeliveryCarrier,
subcarrier,
).rate_shipment(order)
def send_shipping(self, pickings):
"""We have to override this method for redirecting the result to the
proper "child" carrier.
"""
if self.destination_type == "one" or not self:
return super().send_shipping(pickings)
else:
carrier = self.with_context(show_children_carriers=True)
res = []
for p in pickings:
picking_res = False
for subcarrier in carrier.child_ids.filtered(
lambda x: not x.company_id or x.company_id == p.company_id
):
if subcarrier.delivery_type == "fixed":
if subcarrier._match_address(p.partner_id):
picking_res = [
{
"exact_price": subcarrier.fixed_price,
"tracking_number": False,
}
]
break
else:
try:
# on base_on_rule_send_shipping, the method
# _get_price_available is called using p.carrier_id,
# ignoring the self arg, so we need to temporarily replace
# it with the subcarrier
p.carrier_id = subcarrier.id
picking_res = super(
DeliveryCarrier, subcarrier
).send_shipping(p)
break
except Exception: # pylint: disable=except-pass
pass
finally:
p.carrier_id = carrier
if not picking_res:
raise ValidationError(_("There is no matching delivery rule."))
res += picking_res
return res
| 41.104839 | 5,097 |
602 |
py
|
PYTHON
|
15.0
|
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
import logging
_logger = logging.getLogger(__name__)
try:
from odoo.addons.base_multi_company import hooks
except ImportError:
_logger.info("Cannot find `base_multi_company` module in addons path.")
def post_init_hook(cr, registry):
hooks.post_init_hook(
cr,
"product.product_comp_rule",
"product.template",
)
def uninstall_hook(cr, registry):
hooks.uninstall_hook(
cr,
"product.product_comp_rule",
)
| 23.153846 | 602 |
659 |
py
|
PYTHON
|
15.0
|
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
"name": "Product multi-company",
"summary": "Select individually the product template visibility on each " "company",
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/multi-company",
"category": "Product Management",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"depends": ["base_multi_company", "product", "stock"],
"data": ["views/product_template_view.xml"],
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
}
| 41.1875 | 659 |
2,592 |
py
|
PYTHON
|
15.0
|
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# Copyright 2021 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.exceptions import AccessError
from odoo.tests import common
from .common import ProductMultiCompanyCommon
class TestProductMultiCompany(ProductMultiCompanyCommon, common.TransactionCase):
def test_create_product(self):
product = self.env["product.product"].create({"name": "Test"})
company = self.env.company
self.assertTrue(company.id in product.company_ids.ids)
def test_company_none(self):
self.assertFalse(self.product_company_none.company_id)
# All of this should be allowed
self.product_company_none.with_user(
self.user_company_1.id
).description_sale = "Test 1"
self.product_company_none.with_user(
self.user_company_2.id
).description_sale = "Test 2"
def test_company_1(self):
self.assertEqual(
self.product_company_1.with_user(self.user_company_1).company_id,
self.company_1,
)
# All of this should be allowed
self.product_company_1.with_user(
self.user_company_1
).description_sale = "Test 1"
self.product_company_both.with_user(
self.user_company_1
).description_sale = "Test 2"
# And this one not
with self.assertRaises(AccessError):
self.product_company_2.with_user(
self.user_company_1
).description_sale = "Test 3"
def test_company_2(self):
self.assertEqual(
self.product_company_2.with_user(self.user_company_2).company_id,
self.company_2,
)
# All of this should be allowed
self.product_company_2.with_user(
self.user_company_2
).description_sale = "Test 1"
self.product_company_both.with_user(
self.user_company_2
).description_sale = "Test 2"
# And this one not
with self.assertRaises(AccessError):
self.product_company_1.with_user(
self.user_company_2
).description_sale = "Test 3"
def test_uninstall(self):
from ..hooks import uninstall_hook
uninstall_hook(self.env.cr, None)
rule = self.env.ref("product.product_comp_rule")
domain = (
" ['|', ('company_id', '=', user.company_id.id), "
"('company_id', '=', False)]"
)
self.assertEqual(rule.domain_force, domain)
| 36 | 2,592 |
2,446 |
py
|
PYTHON
|
15.0
|
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# Copyright 2021 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
class ProductMultiCompanyCommon(object):
@classmethod
def _create_products(cls):
cls.product_obj = cls.env["product.product"]
cls.product_company_none = cls.product_obj.create(
{
"name": "Product without company",
"company_ids": [(6, 0, [])],
"company_id": False,
}
)
cls.product_company_1 = cls.product_obj.with_company(cls.company_1).create(
{
"name": "Product from company 1",
"company_ids": [(6, 0, cls.company_1.ids)],
}
)
cls.product_company_2 = cls.product_obj.with_company(cls.company_2).create(
{
"name": "Product from company 2",
"company_ids": [(6, 0, cls.company_2.ids)],
}
)
cls.product_company_both = cls.product_obj.create(
{
"name": "Product for both companies",
"company_ids": [(6, 0, (cls.company_1 + cls.company_2).ids)],
}
)
@classmethod
def _create_users(cls):
cls.user_company_1 = cls.env["res.users"].create(
{
"name": "User company 1",
"login": "user_company_1",
"groups_id": [(6, 0, cls.groups.ids)],
"company_id": cls.company_1.id,
"company_ids": [(6, 0, cls.company_1.ids)],
}
)
cls.user_company_2 = cls.env["res.users"].create(
{
"name": "User company 2",
"login": "user_company_2",
"groups_id": [(6, 0, cls.groups.ids)],
"company_id": cls.company_2.id,
"company_ids": [(6, 0, cls.company_2.ids)],
}
)
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.groups = cls.env.ref("base.group_system")
cls.company_obj = cls.env["res.company"]
cls.company_1 = cls.company_obj.create({"name": "Test company 1"})
cls.company_2 = cls.company_obj.create({"name": "Test company 2"})
cls._create_products()
cls._create_users()
| 37.060606 | 2,446 |
763 |
py
|
PYTHON
|
15.0
|
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import fields, models
class ProductCategory(models.Model):
_inherit = "product.category"
total_route_ids = fields.Many2many(
domain=lambda self: [
"|",
("company_id", "=", False),
("company_id", "in", self.env.companies.ids),
]
)
route_ids = fields.Many2many(
"stock.location.route",
"stock_location_route_categ",
"categ_id",
"route_id",
"Routes",
domain=lambda self: [
"|",
("company_id", "=", False),
("company_id", "in", self.env.companies.ids),
],
)
| 26.310345 | 763 |
341 |
py
|
PYTHON
|
15.0
|
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import models
class ProductTemplate(models.Model):
_inherit = ["multi.company.abstract", "product.template"]
_name = "product.template"
_description = "Product Template (Multi-Company)"
| 34.1 | 341 |
2,483 |
py
|
PYTHON
|
15.0
|
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# Copyright 2017 LasLabs Inc.
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html
from odoo import SUPERUSER_ID, api
__all__ = [
"post_init_hook",
"uninstall_hook",
]
def set_security_rule(env, rule_ref):
"""Set the condition for multi-company in the security rule.
:param: env: Environment
:param: rule_ref: XML-ID of the security rule to change.
"""
rule = env.ref(rule_ref)
if not rule: # safeguard if it's deleted
return
rule.write(
{
"active": True,
"domain_force": (
"['|', ('no_company_ids', '=', True), ('company_ids', "
"'in', company_ids)]"
),
}
)
def post_init_hook(cr, rule_ref, model_name):
"""Set the `domain_force` and default `company_ids` to `company_id`.
Args:
cr (Cursor): Database cursor to use for operation.
rule_ref (string): XML ID of security rule to write the
`domain_force` from.
model_name (string): Name of Odoo model object to search for
existing records.
"""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
set_security_rule(env, rule_ref)
# Copy company values
model = env[model_name]
table_name = model._fields["company_ids"].relation
column1 = model._fields["company_ids"].column1
column2 = model._fields["company_ids"].column2
SQL = """
INSERT INTO {}
({}, {})
SELECT id, company_id FROM {} WHERE company_id IS NOT NULL
""".format(
table_name,
column1,
column2,
model._table,
)
env.cr.execute(SQL)
def uninstall_hook(cr, rule_ref):
"""Restore product rule to base value.
Args:
cr (Cursor): Database cursor to use for operation.
rule_ref (string): XML ID of security rule to remove the
`domain_force` from.
"""
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
# Change access rule
rule = env.ref(rule_ref)
rule.write(
{
"active": False,
"domain_force": (
" ['|', ('company_id', '=', user.company_id.id),"
" ('company_id', '=', False)]"
),
}
)
| 29.915663 | 2,483 |
566 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
"name": "Multi Company Base",
"summary": "Provides a base for adding multi-company support to models.",
"version": "15.0.1.0.1",
"author": "ACSONE SA/NV, LasLabs, Tecnativa, Odoo Community Association (OCA)",
"category": "base",
"website": "https://github.com/OCA/multi-company",
"license": "LGPL-3",
"installable": True,
"application": False,
"development_status": "Production/Stable",
"maintainers": ["pedrobaeza"],
}
| 35.375 | 566 |
372 |
py
|
PYTHON
|
15.0
|
# Copyright 2018-19 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class MultiCompanyAbstractTester(models.Model):
_name = "multi.company.abstract.tester"
_inherit = "multi.company.abstract"
_description = "Multi Company Abstract Tester"
name = fields.Char()
| 31 | 372 |
8,667 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 LasLabs Inc.
# Copyright 2021 ACSONE SA/NV
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html
from odoo_test_helper import FakeModelLoader
from odoo.tests import common
class TestMultiCompanyAbstract(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
# The fake class is imported here !! After the backup_registry
from .multi_company_abstract_tester import MultiCompanyAbstractTester
cls.loader.update_registry((MultiCompanyAbstractTester,))
cls.test_model = cls.env["multi.company.abstract.tester"]
cls.tester_model = cls.env["ir.model"].search(
[("model", "=", "multi.company.abstract.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,
}
)
cls.record_1 = cls.test_model.create({"name": "test"})
cls.company_1 = cls.env.company
cls.company_2 = cls.env["res.company"].create(
{"name": "Test Co 2", "email": "[email protected]"}
)
@classmethod
def tearDownClass(cls):
cls.loader.restore_registry()
return super().tearDownClass()
def add_company(self, company):
"""Add company to the test record."""
self.record_1.company_ids = [(4, company.id)]
def switch_user_company(self, user, company):
"""Add a company to the user's allowed & set to current."""
user.write(
{
"company_ids": [(6, 0, (company + user.company_ids).ids)],
"company_id": company.id,
}
)
def test_compute_company_id(self):
"""It should set company_id to the top of the company_ids stack."""
self.add_company(self.company_2)
self.env.user.company_ids = [(4, self.company_2.id)]
self.env.user.company_id = self.company_2.id
self.assertEqual(
self.record_1.company_id.id,
self.company_2.id,
)
def test_search_company_id(self):
"""It should return correct record by searching company_id."""
self.add_company(self.company_2)
record = self.test_model.search(
[
("company_id.email", "=", self.company_2.email),
("id", "=", self.record_1.id),
]
)
self.assertEqual(record, self.record_1)
record = self.test_model.search(
[("company_id", "=", self.company_2.id), ("id", "=", self.record_1.id)]
)
self.assertEqual(record, self.record_1)
record = self.test_model.search(
[
("company_ids", "child_of", self.company_2.id),
("id", "=", self.record_1.id),
]
)
self.assertEqual(record, self.record_1)
record = self.test_model.search(
[
("company_ids", "parent_of", self.company_2.id),
("id", "=", self.record_1.id),
]
)
self.assertEqual(record, self.record_1)
name_result = self.test_model.name_search(
"test", [["company_id", "in", [self.company_2.id]]]
)
# Result is [(<id>, "test")]
self.assertEqual(name_result[0][0], self.record_1.id)
def test_compute_company_id2(self):
"""
Test the computation of company_id for a multi_company_abstract.
We have to ensure that the priority of the computed company_id field
is given on the current company of the current user.
And not a random company into allowed companies (company_ids of the
target model).
Because most of access rights are based on the current company of the
current user and not on allowed companies (company_ids).
:return: bool
"""
user_obj = self.env["res.users"]
company_obj = self.env["res.company"]
company1 = self.env.ref("base.main_company")
# Create companies
company2 = company_obj.create({"name": "High salaries"})
company3 = company_obj.create({"name": "High salaries, twice more!"})
company4 = company_obj.create({"name": "No salaries"})
companies = company1 + company2 + company3
# Create a "normal" user (not the admin)
user = user_obj.create(
{
"name": "Best employee",
"login": "[email protected]",
"company_id": company1.id,
"company_ids": [(6, False, companies.ids)],
}
)
tester_obj = self.test_model.with_user(user)
tester = tester_obj.create(
{"name": "My tester", "company_ids": [(6, False, companies.ids)]}
)
# Current company_id should be updated with current company of the user
for company in user.company_ids:
user.write({"company_id": company.id})
# Force recompute
tester.invalidate_cache()
# Ensure that the current user is on the right company
self.assertEqual(user.company_id, company)
self.assertEqual(tester.company_id, company)
# So can read company fields without Access error
self.assertTrue(bool(tester.company_id.name))
# Switch to a company not in tester.company_ids
self.switch_user_company(user, company4)
# Force recompute
tester.invalidate_cache()
self.assertNotEqual(user.company_id.id, tester.company_ids.ids)
self.assertTrue(bool(tester.company_id.id))
self.assertTrue(bool(tester.company_id.name))
self.assertNotIn(user.company_id.id, tester.company_ids.ids)
def test_company_id_create(self):
"""
Test object creation with both company_ids and company_id
:return: bool
"""
user_obj = self.env["res.users"]
company_obj = self.env["res.company"]
company1 = self.env.ref("base.main_company")
# Create companies
company2 = company_obj.create({"name": "High salaries"})
company3 = company_obj.create({"name": "High salaries, twice more!"})
companies = company1 + company2 + company3
# Create a "normal" user (not the admin)
user = user_obj.create(
{
"name": "Best employee",
"login": "[email protected]",
"company_id": company1.id,
"company_ids": [(6, False, companies.ids)],
}
)
tester_obj = self.test_model.with_user(user)
# We add both values
tester = tester_obj.create(
{
"name": "My tester",
"company_id": company1.id,
"company_ids": [(6, False, companies.ids)],
}
)
# Check if all companies have been added
self.assertEqual(tester.sudo().company_ids, companies)
def test_set_company_id(self):
"""
Test object creation with both company_ids and company_id
:return: bool
"""
user_obj = self.env["res.users"]
company_obj = self.env["res.company"]
company1 = self.env.ref("base.main_company")
# Create companies
company2 = company_obj.create({"name": "High salaries"})
company3 = company_obj.create({"name": "High salaries, twice more!"})
companies = company1 + company2 + company3
# Create a "normal" user (not the admin)
user = user_obj.create(
{
"name": "Best employee",
"login": "[email protected]",
"company_id": company1.id,
"company_ids": [(6, False, companies.ids)],
}
)
tester_obj = self.test_model.with_user(user)
# We add both values
tester = tester_obj.create(
{"name": "My tester", "company_ids": [(6, False, companies.ids)]}
)
# Check if all companies have been added
self.assertEqual(tester.sudo().company_ids, companies)
# Check set company_id
tester.company_id = company1
self.assertEqual(tester.sudo().company_ids, company1)
# Check remove company_id
tester.company_id = False
self.assertFalse(tester.sudo().company_ids)
| 37.197425 | 8,667 |
4,343 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
class MultiCompanyAbstract(models.AbstractModel):
_name = "multi.company.abstract"
_description = "Multi-Company Abstract"
company_id = fields.Many2one(
string="Company",
comodel_name="res.company",
compute="_compute_company_id",
search="_search_company_id",
inverse="_inverse_company_id",
)
company_ids = fields.Many2many(
string="Companies",
comodel_name="res.company",
default=lambda self: self._default_company_ids(),
)
# TODO: Remove it following https://github.com/odoo/odoo/pull/81344
no_company_ids = fields.Boolean(
string="No Companies",
compute="_compute_no_company_ids",
compute_sudo=True,
store=True,
index=True,
)
@api.depends("company_ids")
def _compute_no_company_ids(self):
for record in self:
if record.company_ids:
record.no_company_ids = False
else:
record.no_company_ids = True
def _default_company_ids(self):
return self.browse(self.env.company.ids)
@api.depends("company_ids")
@api.depends_context("company")
def _compute_company_id(self):
for record in self:
# Give the priority of the current company of the user to avoid
# multi company incompatibility errors.
company_id = self.env.context.get("force_company") or self.env.company.id
if company_id in record.company_ids.ids:
record.company_id = company_id
else:
record.company_id = record.company_ids[:1].id
def _inverse_company_id(self):
# To allow modifying allowed companies by non-aware base_multi_company
# through company_id field we:
# - Remove all companies, then add the provided one
for record in self:
record.company_ids = [(6, 0, record.company_id.ids)]
def _search_company_id(self, operator, value):
return [("company_ids", operator, value)]
@api.model_create_multi
def create(self, vals_list):
"""Discard changes in company_id field if company_ids has been given."""
for vals in vals_list:
if "company_ids" in vals and "company_id" in vals:
del vals["company_id"]
return super().create(vals_list)
def write(self, vals):
"""Discard changes in company_id field if company_ids has been given."""
if "company_ids" in vals and "company_id" in vals:
del vals["company_id"]
return super().write(vals)
@api.model
def _name_search(
self, name, args=None, operator="ilike", limit=100, name_get_uid=None
):
# In some situations the 'in' operator is used with company_id in a
# name_search. ORM does not convert to a proper WHERE clause when using
# the 'in' operator.
# e.g: ```
# WHERE "res_partner"."id" in (SELECT "res_partner_id"
# FROM "res_company_res_partner_rel" WHERE "res_company_id" IN (False, 1)
# ```
# patching the args to expand the cumbersome args int a OR clause fix
# the issue.
# e.g: ```
# WHERE "res_partner"."id" not in (SELECT "res_partner_id"
# FROM "res_company_res_partner_rel"
# where "res_partner_id" is not null)
# OR ("res_partner"."id" in (SELECT "res_partner_id"
# FROM "res_company_res_partner_rel" WHERE "res_company_id" IN 1)
# ```
new_args = []
if args is None:
args = []
for arg in args:
if type(arg) == list and arg[:2] == ["company_id", "in"]:
fix = []
for _i in range(len(arg[2]) - 1):
fix.append("|")
for val in arg[2]:
fix.append(["company_id", "=", val])
new_args.extend(fix)
else:
new_args.append(arg)
return super()._name_search(
name,
args=new_args,
operator=operator,
limit=limit,
name_get_uid=name_get_uid,
)
| 36.495798 | 4,343 |
1,064 |
py
|
PYTHON
|
15.0
|
import logging
from odoo import SUPERUSER_ID, api
_logger = logging.getLogger(__name__)
try:
from odoo.addons.base_multi_company import hooks
except ImportError:
_logger.info("Cannot find `base_multi_company` module in addons path.")
def post_init_hook(cr, registry):
hooks.post_init_hook(
cr,
"base.res_partner_rule",
"res.partner",
)
def uninstall_hook(cr, registry):
"""Restore product rule to base value.
Args:
cr (Cursor): Database cursor to use for operation.
rule_ref (string): XML ID of security rule to remove the
`domain_force` from.
"""
env = api.Environment(cr, SUPERUSER_ID, {})
# Change access rule
rule = env.ref("base.res_partner_rule")
rule.write(
{
"active": False,
"domain_force": (
"['|','|',('company_id.child_ids','child_of',"
"[user.company_id.id]),('company_id','child_of',"
"[user.company_id.id]),('company_id','=',False)]"
),
}
)
| 25.95122 | 1,064 |
684 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Oihane Crucelaegui
# Copyright 2015-2019 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
"name": "Partner multi-company",
"summary": "Select individually the partner visibility on each company",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"depends": ["base_multi_company"],
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/multi-company",
"category": "Partner Management",
"data": ["views/res_partner_view.xml"],
"installable": True,
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
}
| 38 | 684 |
7,170 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Oihane Crucelaegui
# Copyright 2015-2019 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.exceptions import AccessError
from odoo.tests import common, tagged
@tagged("post_install", "-at_install")
class TestPartnerMultiCompany(common.TransactionCase):
@classmethod
def setUpClass(cls):
super(TestPartnerMultiCompany, cls).setUpClass()
# Avoid possible spam
cls.partner_model = cls.env["res.partner"].with_context(
mail_create_nosubscribe=True,
)
cls.company_1 = cls.env["res.company"].create({"name": "Test company 1"})
cls.company_2 = cls.env["res.company"].create({"name": "Test company 2"})
cls.partner_company_none = cls.partner_model.create(
{"name": "partner without company", "company_ids": False}
)
cls.partner_company_1 = cls.partner_model.create(
{
"name": "partner from company 1",
"company_ids": [(6, 0, cls.company_1.ids)],
}
)
cls.partner_company_2 = cls.partner_model.create(
{
"name": "partner from company 2",
"company_ids": [(6, 0, cls.company_2.ids)],
}
)
cls.partner_company_both = cls.partner_model.create(
{
"name": "partner for both companies",
"company_ids": [(6, 0, (cls.company_1 + cls.company_2).ids)],
}
)
cls.user_company_1 = cls.env["res.users"].create(
{
"name": "User company 1",
"login": "user_company_1",
"email": "[email protected]",
"groups_id": [
(4, cls.env.ref("base.group_partner_manager").id),
(4, cls.env.ref("base.group_user").id),
],
"company_id": cls.company_1.id,
"company_ids": [(6, 0, cls.company_1.ids)],
}
)
cls.user_company_2 = cls.env["res.users"].create(
{
"name": "User company 2",
"login": "user_company_2",
"email": "[email protected]",
"groups_id": [
(4, cls.env.ref("base.group_partner_manager").id),
(4, cls.env.ref("base.group_user").id),
],
"company_id": cls.company_2.id,
"company_ids": [(6, 0, cls.company_2.ids)],
}
)
cls.partner_company_1 = cls.partner_company_1.with_user(cls.user_company_1)
cls.partner_company_2 = cls.partner_company_2.with_user(cls.user_company_2)
def test_create_partner(self):
partner = self.env["res.partner"].create(
{"name": "Test", "company_ids": [(4, self.env.company.id)]}
)
company = self.env.company
self.assertIn(company.id, partner.company_ids.ids)
partner = self.env["res.partner"].create(
{"name": "Test 2", "company_ids": [(4, self.company_1.id)]}
)
self.assertEqual(
partner.with_user(self.user_company_1).company_id.id,
self.company_1.id,
)
partner = self.env["res.partner"].create(
{"name": "Test 2", "company_ids": [(5, False)]}
)
self.assertFalse(partner.company_id)
def test_company_none(self):
self.assertFalse(self.partner_company_none.company_id)
# All of this should be allowed
self.partner_company_none.with_user(self.user_company_1.id).name = "Test"
self.partner_company_none.with_user(self.user_company_2.id).name = "Test"
def test_company_1(self):
self.assertEqual(self.partner_company_1.company_id, self.company_1)
# All of this should be allowed
self.partner_company_1.with_user(self.user_company_1).name = "Test"
self.partner_company_both.with_user(self.user_company_1).name = "Test"
# And this one not
with self.assertRaises(AccessError):
self.partner_company_2.with_user(self.user_company_1).name = "Test"
def test_create_company_1(self):
partner = self.partner_model.with_user(self.user_company_1).create(
{
"name": "Test from user company 1",
"company_ids": [(6, 0, self.company_1.ids)],
}
)
self.assertEqual(partner.company_id, self.company_1)
def test_create_company_2(self):
partner = self.partner_model.with_user(self.user_company_2).create(
{
"name": "Test from user company 2",
"company_ids": [(6, 0, self.company_2.ids)],
}
)
self.assertEqual(partner.company_id, self.company_2)
def test_company_2(self):
self.assertEqual(self.partner_company_2.company_id, self.company_2)
# All of this should be allowed
self.partner_company_2.with_user(self.user_company_2).name = "Test"
self.partner_company_both.with_user(self.user_company_2).name = "Test"
# And this one not
with self.assertRaises(AccessError):
self.partner_company_1.with_user(self.user_company_2).name = "Test"
def test_uninstall(self):
from ..hooks import uninstall_hook
uninstall_hook(self.env.cr, None)
rule = self.env.ref("base.res_partner_rule")
domain = (
"['|','|',"
"('company_id.child_ids','child_of',[user.company_id.id]),"
"('company_id','child_of',[user.company_id.id]),"
"('company_id','=',False)]"
)
self.assertEqual(rule.domain_force, domain)
self.assertFalse(rule.active)
def test_switch_user_company(self):
self.user_company_1.company_ids = (self.company_1 + self.company_2).ids
self.user_company_1.company_id = self.company_2.id
self.user_company_1 = self.user_company_1.with_user(self.user_company_2)
self.assertEqual(
self.user_company_1.partner_id.company_id,
self.company_2,
)
def test_commercial_fields_implementation(self):
"""It should add company_ids to commercial fields."""
self.assertIn(
"company_ids",
self.env["res.partner"]._commercial_fields(),
)
def test_commercial_fields_result(self):
"""It should add company_ids to children partners."""
partner = self.env["res.partner"].create(
{"name": "Child test", "parent_id": self.partner_company_both.id}
)
self.assertEqual(
partner.company_ids,
self.partner_company_both.company_ids,
)
def test_avoid_updating_company_ids_in_global_partners(self):
self.user_company_1.write({"company_ids": [(4, self.company_2.id)]})
user_partner = self.user_company_1.partner_id
user_partner.write({"company_id": False, "company_ids": [(5, False)]})
self.user_company_1.write({"company_id": self.company_2.id})
self.assertEqual(user_partner.company_ids.ids, [])
| 40.971429 | 7,170 |
1,032 |
py
|
PYTHON
|
15.0
|
# Copyright 2015-2016 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html.html
from odoo import api, models
class ResUsers(models.Model):
_inherit = "res.users"
@api.model
def create(self, vals):
res = super(ResUsers, self).create(vals)
if "company_ids" in vals:
res.partner_id.company_ids = vals["company_ids"]
if "company_id" in vals and res.partner_id.company_ids:
res.partner_id.company_id = vals["company_id"]
return res
def write(self, vals):
res = super(ResUsers, self).write(vals)
if "company_ids" in vals:
for user in self.sudo():
if user.partner_id.company_ids:
user.partner_id.company_ids = vals["company_ids"]
if "company_id" in vals:
for user in self.sudo():
if user.partner_id.company_ids:
user.partner_id.company_ids = [(4, vals["company_id"])]
return res
| 35.586207 | 1,032 |
2,260 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Oihane Crucelaegui
# Copyright 2015-2019 Pedro M. Baeza <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html.html
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = ["multi.company.abstract", "res.partner"]
_name = "res.partner"
# This is needed because after installation this field becomes
# unsearchable and unsortable. Which is not explicitly changed in this
# module and as such can be considered an undesired yield.
display_name = fields.Char(
compute="_compute_display_name",
store=True,
index=True,
)
@api.model
def create(self, vals):
"""Neutralize the default value applied to company_id that can't be
removed in the inheritance, and that will activate the inverse method,
overwriting our company_ids field desired value.
"""
vals = self._amend_company_id(vals)
return super().create(vals)
@api.model
def _commercial_fields(self):
"""Add company_ids to the commercial fields that will be synced with
childs. Ideal would be that this field is isolated from company field,
but it involves a lot of development (default value, incoherences
parent/child...).
:return: List of field names to be synced.
"""
fields = super(ResPartner, self)._commercial_fields()
fields += ["company_ids"]
return fields
@api.model
def _amend_company_id(self, vals):
if "company_ids" in vals:
if not vals["company_ids"]:
vals["company_id"] = False
else:
for item in vals["company_ids"]:
if item[0] in (1, 4):
vals["company_id"] = item[1]
elif item[0] in (2, 3, 5):
vals["company_id"] = False
elif item[0] == 6:
if item[2]:
vals["company_id"] = item[2][0]
else: # pragma: no cover
vals["company_id"] = False
elif "company_id" not in vals:
vals["company_ids"] = False
return vals
| 37.666667 | 2,260 |
735 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Inter Company Module for Purchase to Sale Order with warehouse",
"summary": "Intercompany PO/SO rules with warehouse",
"version": "15.0.1.0.0",
"category": "Purchase Management",
"website": "https://github.com/OCA/multi-company",
"author": "Odoo SA, Akretion, Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"auto_install": True,
"depends": ["purchase_sale_inter_company", "sale_stock", "purchase_stock"],
"data": ["views/res_config_view.xml"],
}
| 40.833333 | 735 |
2,618 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2019-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.addons.purchase_sale_inter_company.tests.test_inter_company_purchase_sale import (
TestPurchaseSaleInterCompany,
)
class TestPurchaseSaleStockInterCompany(TestPurchaseSaleInterCompany):
@classmethod
def _create_warehouse(cls, code, company):
address = cls.env["res.partner"].create({"name": f"{code} address"})
return cls.env["stock.warehouse"].create(
{
"name": f"Warehouse {code}",
"code": code,
"partner_id": address.id,
"company_id": company.id,
}
)
@classmethod
def setUpClass(cls):
super().setUpClass()
# Configure 2 Warehouse per company
cls.warehouse_a = cls.env["stock.warehouse"].search(
[("company_id", "=", cls.company_a.id)]
)
cls.warehouse_b = cls._create_warehouse("CA-WB", cls.company_a)
cls.warehouse_c = cls.env["stock.warehouse"].search(
[("company_id", "=", cls.company_b.id)]
)
cls.warehouse_d = cls._create_warehouse("CB-WD", cls.company_b)
cls.company_b.warehouse_id = cls.warehouse_c
def test_deliver_to_warehouse_a(self):
self.purchase_company_a.picking_type_id = self.warehouse_a.in_type_id
sale = self._approve_po()
self.assertEqual(self.warehouse_a.partner_id, sale.partner_shipping_id)
def test_deliver_to_warehouse_b(self):
self.purchase_company_a.picking_type_id = self.warehouse_b.in_type_id
sale = self._approve_po()
self.assertEqual(self.warehouse_b.partner_id, sale.partner_shipping_id)
def test_send_from_warehouse_c(self):
self.company_b.warehouse_id = self.warehouse_c
sale = self._approve_po()
self.assertEqual(sale.warehouse_id, self.warehouse_c)
def test_send_from_warehouse_d(self):
self.company_b.warehouse_id = self.warehouse_d
sale = self._approve_po()
self.assertEqual(sale.warehouse_id, self.warehouse_d)
def test_purchase_sale_stock_inter_company(self):
self.purchase_company_a.notes = "Test note"
sale = self._approve_po()
self.assertEqual(
sale.partner_shipping_id,
self.purchase_company_a.picking_type_id.warehouse_id.partner_id,
)
self.assertEqual(sale.warehouse_id, self.warehouse_c)
| 38.5 | 2,618 |
1,052 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
def _prepare_sale_order_data(
self, name, partner, dest_company, direct_delivery_address
):
new_order = super()._prepare_sale_order_data(
name, partner, dest_company, direct_delivery_address
)
delivery_address = (
direct_delivery_address
or self.picking_type_id.warehouse_id.partner_id
or False
)
if delivery_address:
new_order.update({"partner_shipping_id": delivery_address.id})
warehouse = (
dest_company.warehouse_id.company_id == dest_company
and dest_company.warehouse_id
or False
)
if warehouse:
new_order.update({"warehouse_id": warehouse.id})
return new_order
| 32.875 | 1,052 |
533 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResCompany(models.Model):
_inherit = "res.company"
warehouse_id = fields.Many2one(
"stock.warehouse",
string="Warehouse For Sale Orders",
help="Default value to set on Sale Orders that "
"will be created based on Purchase Orders made to this company",
)
| 29.611111 | 533 |
2,406 |
py
|
PYTHON
|
15.0
|
# Copyright 2018 Tecnativa - Carlos Dauden
# Copyright 2018 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, fields, models
from odoo.exceptions import UserError
class StockPicking(models.Model):
_inherit = "stock.picking"
intercompany_picking_id = fields.Many2one(comodel_name="stock.picking")
def action_done(self):
# Only DropShip pickings
po_picks = self.browse()
for pick in self.filtered(
lambda x: x.location_dest_id.usage == "customer"
).sudo():
purchase = pick.sale_id.auto_purchase_order_id
if not purchase:
continue
purchase.picking_ids.write({"intercompany_picking_id": pick.id})
for move_line in pick.move_line_ids:
qty_done = move_line.qty_done
sale_line_id = move_line.move_id.sale_line_id
po_move_lines = sale_line_id.auto_purchase_line_id.move_ids.mapped(
"move_line_ids"
)
for po_move_line in po_move_lines:
if po_move_line.product_qty >= qty_done:
po_move_line.qty_done = qty_done
qty_done = 0.0
else:
po_move_line.qty_done = po_move_line.product_qty
qty_done -= po_move_line.product_qty
po_picks |= po_move_line.picking_id
if qty_done and po_move_lines:
po_move_lines[-1:].qty_done += qty_done
elif not po_move_lines:
raise UserError(
_(
"There's no corresponding line in PO %(po)s for assigning "
"qty from %(pick_name)s for product %(product)s"
)
% (
{
"po": purchase.name,
"pick_name": pick.name,
"product": move_line.product_id.name,
}
)
)
# Transfer dropship pickings
for po_pick in po_picks.sudo():
po_pick.with_company(po_pick.company_id.id).action_done()
return super(StockPicking, self).action_done()
| 42.210526 | 2,406 |
644 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class InterCompanyRulesConfig(models.TransientModel):
_inherit = "res.config.settings"
warehouse_id = fields.Many2one(
comodel_name="stock.warehouse",
related="company_id.warehouse_id",
string="Warehouse for Sale Orders",
help="Default value to set on Sale Orders that will be created "
"based on Purchase Orders made to this company.",
readonly=False,
)
| 32.2 | 644 |
1,068 |
py
|
PYTHON
|
15.0
|
import setuptools
with open('VERSION.txt', 'r') as f:
version = f.read().strip()
setuptools.setup(
name="odoo-addons-oca-multi-company",
description="Meta package for oca-multi-company Odoo addons",
version=version,
install_requires=[
'odoo-addon-account_invoice_inter_company>=15.0dev,<15.1dev',
'odoo-addon-account_multicompany_easy_creation>=15.0dev,<15.1dev',
'odoo-addon-base_multi_company>=15.0dev,<15.1dev',
'odoo-addon-mail_template_multi_company>=15.0dev,<15.1dev',
'odoo-addon-partner_multi_company>=15.0dev,<15.1dev',
'odoo-addon-product_multi_company>=15.0dev,<15.1dev',
'odoo-addon-product_tax_multicompany_default>=15.0dev,<15.1dev',
'odoo-addon-purchase_sale_inter_company>=15.0dev,<15.1dev',
'odoo-addon-purchase_sale_stock_inter_company>=15.0dev,<15.1dev',
'odoo-addon-stock_intercompany>=15.0dev,<15.1dev',
],
classifiers=[
'Programming Language :: Python',
'Framework :: Odoo',
'Framework :: Odoo :: 15.0',
]
)
| 39.555556 | 1,068 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
704 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-2014 Odoo SA
# Copyright 2015-2017 Chafique Delli <[email protected]>
# Copyright 2020 Tecnativa - David Vidal
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Inter Company Invoices",
"summary": "Intercompany invoice rules",
"version": "15.0.1.0.2",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/multi-company",
"author": "Odoo SA, Akretion, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["account", "base_setup"],
"data": ["views/account_move_views.xml", "views/res_config_settings_view.xml"],
"installable": True,
}
| 39.111111 | 704 |
23,874 |
py
|
PYTHON
|
15.0
|
# Copyright 2015-2017 Chafique Delli <[email protected]>
# Copyright 2020 Tecnativa - David Vidal
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import Form, TransactionCase
class TestAccountInvoiceInterCompanyBase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.account_obj = cls.env["account.account"]
cls.account_move_obj = cls.env["account.move"]
cls.chart = cls.env["account.chart.template"].search([], limit=1)
if not cls.chart:
raise ValidationError(
# translation to avoid pylint warnings
_("No Chart of Account Template has been defined !")
)
cls.company_a = cls.env["res.company"].create(
{
"name": "Company A",
"currency_id": cls.env.ref("base.EUR").id,
"country_id": cls.env.ref("base.fr").id,
"parent_id": cls.env.ref("base.main_company").id,
"invoice_auto_validation": True,
}
)
cls.chart.try_loading(company=cls.company_a, install_demo=False)
cls.partner_company_a = cls.env["res.partner"].create(
{"name": cls.company_a.name, "is_company": True}
)
cls.company_a.partner_id = cls.partner_company_a
cls.company_b = cls.env["res.company"].create(
{
"name": "Company B",
"currency_id": cls.env.ref("base.EUR").id,
"country_id": cls.env.ref("base.fr").id,
"parent_id": cls.env.ref("base.main_company").id,
"invoice_auto_validation": True,
}
)
cls.chart.try_loading(company=cls.company_b, install_demo=False)
cls.partner_company_b = cls.env["res.partner"].create(
{"name": cls.company_b.name, "is_company": True}
)
cls.child_partner_company_b = cls.env["res.partner"].create(
{
"name": "Child, Company B",
"is_company": False,
"company_id": False,
"parent_id": cls.partner_company_b.id,
}
)
cls.company_b.partner_id = cls.partner_company_b
# cls.partner_company_b = cls.company_b.parent_id.partner_id
cls.user_company_a = cls.env["res.users"].create(
{
"name": "User A",
"login": "usera",
"company_type": "person",
"email": "[email protected]",
"password": "usera_p4S$word",
"company_id": cls.company_a.id,
"company_ids": [(6, 0, [cls.company_a.id])],
"groups_id": [
(
6,
0,
[
cls.env.ref("base.group_partner_manager").id,
cls.env.ref("account.group_account_manager").id,
],
)
],
}
)
cls.user_company_b = cls.env["res.users"].create(
{
"name": "User B",
"login": "userb",
"company_type": "person",
"email": "[email protected]",
"password": "userb_p4S$word",
"company_id": cls.company_b.id,
"company_ids": [(6, 0, [cls.company_b.id])],
"groups_id": [
(
6,
0,
[
cls.env.ref("base.group_partner_manager").id,
cls.env.ref("account.group_account_manager").id,
],
)
],
}
)
cls.sequence_sale_journal_company_a = cls.env["ir.sequence"].create(
{
"name": "Account Sales Journal Company A",
"padding": 3,
"prefix": "SAJ-A/%(year)s/",
"company_id": cls.company_a.id,
}
)
cls.sequence_misc_journaal_company_a = cls.env["ir.sequence"].create(
{
"name": "Miscellaneous Journal Company A",
"padding": 3,
"prefix": "MISC-A/%(year)s/",
"company_id": cls.company_a.id,
}
)
cls.sequence_purchase_journal_company_a = cls.env["ir.sequence"].create(
{
"name": "Account Expenses Journal Company A",
"padding": 3,
"prefix": "EXJ-A/%(year)s/",
"company_id": cls.company_a.id,
}
)
cls.sequence_sale_journal_company_b = cls.env["ir.sequence"].create(
{
"name": "Account Sales Journal Company B",
"padding": 3,
"prefix": "SAJ-B/%(year)s/",
"company_id": cls.company_b.id,
}
)
cls.sequence_misc_journal_company_b = cls.env["ir.sequence"].create(
{
"name": "Miscellaneous Journal Company B",
"padding": 3,
"prefix": "MISC-B/%(year)s/",
"company_id": cls.company_b.id,
}
)
cls.sequence_purchase_journal_company_b = cls.env["ir.sequence"].create(
{
"name": "Account Expenses Journal Company B",
"padding": 3,
"prefix": "EXJ-B/%(year)s/",
"company_id": cls.company_b.id,
}
)
cls.sequence_misc_journal_company_a = cls.env["ir.sequence"].create(
{
"name": "Miscellaneous Journal Company A",
"padding": 3,
"prefix": "MISC-A/%(year)s/",
"company_id": cls.company_a.id,
}
)
cls.sequence_purchase_journal_company_a = cls.env["ir.sequence"].create(
{
"name": "Account Expenses Journal Company A",
"padding": 3,
"prefix": "EXJ-A/%(year)s/",
"company_id": cls.company_a.id,
}
)
cls.sequence_sale_journal_company_b = cls.env["ir.sequence"].create(
{
"name": "Account Sales Journal Company B",
"padding": 3,
"prefix": "SAJ-B/%(year)s/",
"company_id": cls.company_b.id,
}
)
cls.sequence_misc_journal_company_b = cls.env["ir.sequence"].create(
{
"name": "Miscellaneous Journal Company B",
"padding": 3,
"prefix": "MISC-B/%(year)s/",
"company_id": cls.company_b.id,
}
)
cls.sequence_purchase_journal_company_b = cls.env["ir.sequence"].create(
{
"name": "Account Expenses Journal Company B",
"padding": 3,
"prefix": "EXJ-B/%(year)s/",
"company_id": cls.company_b.id,
}
)
cls.a_sale_company_a = cls.account_obj.create(
{
"code": "X2001-A",
"name": "Product Sales - (company A)",
"internal_type": "other",
"user_type_id": cls.env.ref("account.data_account_type_revenue").id,
"company_id": cls.company_a.id,
}
)
cls.a_expense_company_a = cls.account_obj.create(
{
"code": "X2110-A",
"name": "Expenses - (company A)",
"internal_type": "other",
"user_type_id": cls.env.ref("account.data_account_type_expenses").id,
"company_id": cls.company_a.id,
}
)
cls.a_bank_company_a = cls.account_obj.create(
{
"code": "512001-A",
"name": "Bank - (company A)",
"user_type_id": cls.env.ref("account.data_account_type_liquidity").id,
"company_id": cls.company_a.id,
}
)
cls.a_recv_company_b = cls.account_obj.create(
{
"code": "X11002-B",
"name": "Debtors - (company B)",
"internal_type": "receivable",
"reconcile": "True",
"user_type_id": cls.env.ref("account.data_account_type_receivable").id,
"company_id": cls.company_b.id,
}
)
cls.a_pay_company_b = cls.account_obj.create(
{
"code": "X1111-B",
"name": "Creditors - (company B)",
"internal_type": "payable",
"reconcile": "True",
"user_type_id": cls.env.ref("account.data_account_type_payable").id,
"company_id": cls.company_b.id,
}
)
cls.a_sale_company_b = cls.account_obj.create(
{
"code": "X2001-B",
"name": "Product Sales - (company B)",
"internal_type": "other",
"user_type_id": cls.env.ref("account.data_account_type_revenue").id,
"company_id": cls.company_b.id,
}
)
cls.a_expense_company_b = cls.account_obj.create(
{
"code": "X2110-B",
"name": "Expenses - (company B)",
"internal_type": "other",
"user_type_id": cls.env.ref("account.data_account_type_expenses").id,
"company_id": cls.company_b.id,
}
)
cls.a_bank_company_b = cls.account_obj.create(
{
"code": "512001-B",
"name": "Bank - (company B)",
"user_type_id": cls.env.ref("account.data_account_type_liquidity").id,
"company_id": cls.company_b.id,
}
)
cls.sales_journal_company_a = cls.env["account.journal"].create(
{
"name": "Sales Journal - (Company A)",
"code": "SAJ-A",
"type": "sale",
"secure_sequence_id": cls.sequence_sale_journal_company_a.id,
"default_account_id": cls.a_sale_company_a.id,
"company_id": cls.company_a.id,
}
)
cls.bank_journal_company_a = cls.env["account.journal"].create(
{
"name": "Bank Journal - (Company A)",
"code": "BNK-A",
"type": "bank",
"default_account_id": cls.a_sale_company_a.id,
"company_id": cls.company_a.id,
}
)
cls.misc_journal_company_a = cls.env["account.journal"].create(
{
"name": "Miscellaneous Operations - (Company A)",
"code": "MISC-A",
"type": "general",
"secure_sequence_id": cls.sequence_misc_journal_company_a.id,
"company_id": cls.company_a.id,
}
)
cls.purchases_journal_company_b = cls.env["account.journal"].create(
{
"name": "Purchases Journal - (Company B)",
"code": "EXJ-B",
"type": "purchase",
"secure_sequence_id": cls.sequence_purchase_journal_company_b.id,
"default_account_id": cls.a_expense_company_b.id,
"company_id": cls.company_b.id,
}
)
cls.bank_journal_company_b = cls.env["account.journal"].create(
{
"name": "Bank Journal - (Company B)",
"code": "BNK-B",
"type": "bank",
"default_account_id": cls.a_sale_company_b.id,
"company_id": cls.company_b.id,
}
)
cls.misc_journal_company_b = cls.env["account.journal"].create(
{
"name": "Miscellaneous Operations - (Company B)",
"code": "MISC-B",
"type": "general",
"secure_sequence_id": cls.sequence_misc_journal_company_b.id,
"company_id": cls.company_b.id,
}
)
cls.product_consultant_multi_company = cls.env["product.product"].create(
{
"name": "Service Multi Company",
"uom_id": cls.env.ref("uom.product_uom_hour").id,
"uom_po_id": cls.env.ref("uom.product_uom_hour").id,
"categ_id": cls.env.ref("product.product_category_3").id,
"type": "service",
}
)
# if product_multi_company is installed
if "company_ids" in cls.env["product.template"]._fields:
# We have to do that because the default method added a company
cls.product_consultant_multi_company.company_ids = False
cls.env["ir.sequence"].create(
{
"name": "Account Sales Journal Company A",
"prefix": "SAJ-A/%(year)s/",
"company_id": cls.company_a.id,
}
)
cls.pcg_X58 = cls.env["account.account.template"].create(
{
"name": "Internal Transfers",
"code": "X58",
"user_type_id": cls.env.ref(
"account.data_account_type_current_assets"
).id,
"reconcile": True,
}
)
cls.a_recv_company_a = cls.account_obj.create(
{
"code": "X11002-A",
"name": "Debtors - (company A)",
"internal_type": "receivable",
"reconcile": "True",
"user_type_id": cls.env.ref("account.data_account_type_receivable").id,
"company_id": cls.company_a.id,
}
)
cls.a_pay_company_a = cls.account_obj.create(
{
"code": "X1111-A",
"name": "Creditors - (company A)",
"internal_type": "payable",
"reconcile": "True",
"user_type_id": cls.env.ref("account.data_account_type_payable").id,
"company_id": cls.company_a.id,
}
)
cls.partner_company_a.property_account_receivable_id = cls.a_recv_company_a.id
cls.partner_company_a.property_account_payable_id = cls.a_pay_company_a.id
cls.partner_company_b.property_account_receivable_id = cls.a_recv_company_b.id
cls.partner_company_b.property_account_payable_id = cls.a_pay_company_b.id
cls.invoice_company_a = Form(
cls.account_move_obj.with_company(cls.company_a.id).with_context(
default_move_type="out_invoice",
)
)
cls.invoice_company_a.partner_id = cls.partner_company_b
cls.invoice_company_a.journal_id = cls.sales_journal_company_a
cls.invoice_company_a.currency_id = cls.env.ref("base.EUR")
with cls.invoice_company_a.invoice_line_ids.new() as line_form:
line_form.product_id = cls.product_consultant_multi_company
line_form.quantity = 1
line_form.product_uom_id = cls.env.ref("uom.product_uom_hour")
line_form.account_id = cls.a_sale_company_a
line_form.name = "Service Multi Company"
line_form.price_unit = 450.0
cls.invoice_company_a = cls.invoice_company_a.save()
cls.invoice_line_a = cls.invoice_company_a.invoice_line_ids[0]
cls.company_a.invoice_auto_validation = True
cls.product_a = cls.invoice_line_a.product_id
cls.product_a.with_company(
cls.company_b.id
).property_account_expense_id = cls.a_expense_company_b.id
class TestAccountInvoiceInterCompany(TestAccountInvoiceInterCompanyBase):
def test01_user(self):
# Check user of company B (company of destination)
# with which we check the intercompany product
self.assertNotEqual(self.user_company_b.id, 1)
orig_invoice = self.invoice_company_a
dest_company = orig_invoice._find_company_from_invoice_partner()
self.assertEqual(self.user_company_b.company_id, dest_company)
self.assertIn(
self.user_company_b.id,
self.env.ref("account.group_account_invoice").users.ids,
)
def test02_product(self):
# Check product is intercompany
for line in self.invoice_company_a.invoice_line_ids:
self.assertFalse(line.product_id.company_id)
def test03_confirm_invoice_and_cancel(self):
# ensure the catalog is shared
self.env.ref("product.product_comp_rule").write({"active": False})
# Make sure there are no taxes in target company for the used product
self.product_a.with_company(self.user_company_b.id).supplier_taxes_id = False
# Put some analytic data for checking its propagation
analytic_account = self.env["account.analytic.account"].create(
{"name": "Test analytic account", "company_id": False}
)
analytic_tag = self.env["account.analytic.tag"].create(
{"name": "Test analytic tag", "company_id": False}
)
self.invoice_line_a.analytic_account_id = analytic_account.id
self.invoice_line_a.analytic_tag_ids = [(4, analytic_tag.id)]
# Give user A permission to analytic
self.user_company_a.groups_id = [
(4, self.env.ref("analytic.group_analytic_accounting").id)
]
# Confirm the invoice of company A
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
# Check destination invoice created in company B
invoices = self.account_move_obj.with_user(self.user_company_b.id).search(
[("auto_invoice_id", "=", self.invoice_company_a.id)]
)
self.assertNotEqual(invoices, False)
self.assertEqual(len(invoices), 1)
self.assertEqual(invoices[0].state, "posted")
self.assertEqual(
invoices[0].partner_id,
self.invoice_company_a.company_id.partner_id,
)
self.assertEqual(
invoices[0].company_id.partner_id,
self.invoice_company_a.partner_id,
)
self.assertEqual(
len(invoices[0].invoice_line_ids),
len(self.invoice_company_a.invoice_line_ids),
)
invoice_line = invoices[0].invoice_line_ids[0]
self.assertEqual(
invoice_line.product_id,
self.invoice_company_a.invoice_line_ids[0].product_id,
)
self.assertEqual(
invoice_line.analytic_account_id,
self.invoice_line_a.analytic_account_id,
)
self.assertEqual(
invoice_line.analytic_tag_ids, self.invoice_line_a.analytic_tag_ids
)
# Cancel the invoice of company A
invoice_origin = ("%s - Canceled Invoice: %s") % (
self.invoice_company_a.company_id.name,
self.invoice_company_a.name,
)
self.invoice_company_a.with_user(self.user_company_a.id).button_cancel()
# Check invoices after to cancel invoice of company A
self.assertEqual(self.invoice_company_a.state, "cancel")
self.assertEqual(invoices[0].state, "cancel")
self.assertEqual(invoices[0].invoice_origin, invoice_origin)
# Check if keep the invoice number
invoice_number = self.invoice_company_a.name
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
self.assertEqual(self.invoice_company_a.name, invoice_number)
# When the destination invoice is posted we can't modify the origin either
with self.assertRaises(UserError):
self.invoice_company_a.with_context(breakpoint=True).button_draft()
# Check that we can't modify the destination invoice
dest_invoice = self.account_move_obj.search(
[("auto_invoice_id", "=", self.invoice_company_a.id)]
)
dest_invoice.button_draft()
with self.assertRaises(UserError):
move_form = Form(dest_invoice)
with move_form.invoice_line_ids.edit(0) as line_form:
line_form.price_unit = 33.3
move_form.save()
def test_confirm_invoice_with_child_partner(self):
# ensure the catalog is shared
self.env.ref("product.product_comp_rule").write({"active": False})
# When a contact of the company is defined as partner,
# it also must trigger the intercompany workflow
self.invoice_company_a.write({"partner_id": self.child_partner_company_b.id})
# Confirm the invoice of company A
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
# Check destination invoice created in company B
invoices = self.account_move_obj.with_user(self.user_company_b.id).search(
[("auto_invoice_id", "=", self.invoice_company_a.id)]
)
self.assertEqual(len(invoices), 1)
def test_confirm_invoice_with_product_and_shared_catalog(self):
"""With no security rule, child company have access to any product.
Then child invoice can share the same product
"""
# ensure the catalog is shared even if product is in other company
self.env.ref("product.product_comp_rule").write({"active": False})
# Product is set to a specific company
self.product_a.write({"company_id": self.company_a.id})
invoices = self._confirm_invoice_with_product()
self.assertNotEqual(
invoices.invoice_line_ids[0].product_id, self.env["product.product"]
)
def test_confirm_invoice_with_native_product_rule_and_shared_product(self):
"""With native security rule, products with access in both companies
must be present in parent and child invoices.
"""
# ensure the catalog is shared even if product is in other company
self.env.ref("product.product_comp_rule").write({"active": True})
# Product is set to a specific company
self.product_a.write({"company_id": False})
# If product_multi_company is installed
if "company_ids" in dir(self.product_a):
self.product_a.write({"company_ids": [(5, 0, 0)]})
invoices = self._confirm_invoice_with_product()
self.assertEqual(invoices.invoice_line_ids[0].product_id, self.product_a)
def test_confirm_invoice_with_native_product_rule_and_unshared_product(self):
"""With native security rule, products with no access in both companies
must prevent child invoice creation.
"""
# ensure the catalog is shared even if product is in other company
self.env.ref("product.product_comp_rule").write({"active": True})
# Product is set to a specific company
self.product_a.write({"company_id": self.company_a.id})
# If product_multi_company is installed
if "company_ids" in dir(self.product_a):
self.product_a.write({"company_ids": [(6, 0, [self.company_a.id])]})
with self.assertRaises(UserError):
self._confirm_invoice_with_product()
def _confirm_invoice_with_product(self):
# Confirm the invoice of company A
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
# Check destination invoice created in company B
invoices = self.account_move_obj.with_user(self.user_company_b.id).search(
[("auto_invoice_id", "=", self.invoice_company_a.id)]
)
self.assertEqual(len(invoices), 1)
return invoices
| 41.884211 | 23,874 |
14,857 |
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from odoo import _, api, fields, models
from odoo.exceptions import AccessError, UserError
from odoo.tests.common import Form
from odoo.tools import float_compare
from odoo.tools.misc import clean_context
_logger = logging.getLogger(__name__)
class AccountMove(models.Model):
_inherit = "account.move"
auto_generated = fields.Boolean(
"Auto Generated Document", copy=False, default=False
)
auto_invoice_id = fields.Many2one(
"account.move",
string="Source Invoice",
readonly=True,
copy=False,
prefetch=False,
)
def _find_company_from_invoice_partner(self):
self.ensure_one()
company = (
self.env["res.company"]
.sudo()
.search([("partner_id", "=", self.commercial_partner_id.id)], limit=1)
)
return company or False
def action_post(self):
"""Validated invoice generate cross invoice base on company rules"""
res = super().action_post()
# Intercompany account entries or receipts aren't supported
supported_types = {"out_invoice", "in_invoice", "out_refund", "in_refund"}
for src_invoice in self.filtered(lambda x: x.move_type in supported_types):
# do not consider invoices that have already been auto-generated,
# nor the invoices that were already validated in the past
dest_company = src_invoice._find_company_from_invoice_partner()
if not dest_company or src_invoice.auto_generated:
continue
# We want to avoid creating a new invoice if the destination one was already
# posted
inter_invoice = self.search(
[
("auto_invoice_id", "=", src_invoice.id),
("company_id", "=", dest_company.id),
("state", "=", "posted"),
]
)
if inter_invoice:
continue
intercompany_user = dest_company.intercompany_invoice_user_id
if intercompany_user:
src_invoice = src_invoice.with_user(intercompany_user).sudo()
else:
src_invoice = src_invoice.sudo()
src_invoice.with_company(dest_company.id).with_context(
skip_check_amount_difference=True
)._inter_company_create_invoice(dest_company)
return res
def _check_intercompany_product(self, dest_company):
self.ensure_one()
if dest_company.company_share_product:
return
domain = dest_company._get_user_domain()
dest_user = self.env["res.users"].search(domain, limit=1)
for line in self.invoice_line_ids:
try:
line.sudo(False).with_user(dest_user).with_context(
allowed_company_ids=[dest_company.id]
).product_id.product_tmpl_id.check_access_rule("read")
except AccessError as e:
raise UserError(
_(
"You cannot create invoice in company '%(dest_company_name)s' with "
"product '%(product_name)s' because it is not multicompany"
)
% {
"dest_company_name": dest_company.name,
"product_name": line.product_id.name,
}
) from e
def _inter_company_create_invoice(self, dest_company):
"""create an invoice for the given company : it will copy
the invoice lines in the new invoice.
:param dest_company : the company of the created invoice
:rtype dest_company : res.company record
"""
self.ensure_one()
self = self.with_context(check_move_validity=False)
# check intercompany product
self._check_intercompany_product(dest_company)
# if an invoice has already been generated
# delete it and force the same number
inter_invoice = self.search(
[("auto_invoice_id", "=", self.id), ("company_id", "=", dest_company.id)]
)
force_number = False
if inter_invoice and inter_invoice.state in ["draft", "cancel"]:
force_number = inter_invoice.name
inter_invoice.with_context(force_delete=True).unlink()
# create invoice
dest_invoice_data = self._prepare_invoice_data(dest_company)
if force_number:
dest_invoice_data["name"] = force_number
dest_invoice = self.create(dest_invoice_data)
# create invoice lines
dest_move_line_data = []
for src_line in self.invoice_line_ids.filtered(lambda x: not x.display_type):
if not src_line.product_id:
raise UserError(
_(
"The invoice line '%(line_name)s' doesn't have a product. "
"All invoice lines should have a product for "
"inter-company invoices."
)
% {"line_name": src_line.name}
)
dest_move_line_data.append(
src_line._prepare_account_move_line(dest_invoice, dest_company)
)
self.env["account.move.line"].create(dest_move_line_data)
dest_invoice._move_autocomplete_invoice_lines_values()
# Validation of account invoice
precision = self.env["decimal.precision"].precision_get("Account")
if dest_company.invoice_auto_validation and not float_compare(
self.amount_total, dest_invoice.amount_total, precision_digits=precision
):
dest_invoice.action_post()
else:
# Add warning in chatter if the total amounts are different
if float_compare(
self.amount_total, dest_invoice.amount_total, precision_digits=precision
):
body = _(
"WARNING!!!!! Failure in the inter-company invoice "
"creation process: the total amount of this invoice "
"is %(dest_amount_total)s but the total amount "
"of the invoice %(invoice_name)s "
"in the company %(company_name)s is %(amount_total)s"
) % {
"dest_amount_total": dest_invoice.amount_total,
"invoice_name": self.name,
"company_name": self.company_id.name,
"amount_total": self.amount_total,
}
dest_invoice.message_post(body=body)
return {"dest_invoice": dest_invoice}
def _get_destination_invoice_type(self):
self.ensure_one()
MAP_INVOICE_TYPE = {
"out_invoice": "in_invoice",
"in_invoice": "out_invoice",
"out_refund": "in_refund",
"in_refund": "out_refund",
}
return MAP_INVOICE_TYPE.get(self.move_type)
def _get_destination_journal_type(self):
self.ensure_one()
MAP_JOURNAL_TYPE = {
"out_invoice": "purchase",
"in_invoice": "sale",
"out_refund": "purchase",
"in_refund": "sale",
}
return MAP_JOURNAL_TYPE.get(self.move_type)
def _prepare_invoice_data(self, dest_company):
"""Generate invoice values
:param dest_company : the company of the created invoice
:rtype dest_company : res.company record
"""
self.ensure_one()
self = self.with_context(**clean_context(self.env.context))
dest_inv_type = self._get_destination_invoice_type()
dest_journal_type = self._get_destination_journal_type()
# find the correct journal
dest_journal = self.env["account.journal"].search(
[("type", "=", dest_journal_type), ("company_id", "=", dest_company.id)],
limit=1,
)
if not dest_journal:
raise UserError(
_(
"Please define %(dest_journal_type)s journal for "
'this company: "%(dest_company_name)s" (id:%(dest_company_id)d).'
)
% {
"dest_journal_type": dest_journal_type,
"dest_company_name": dest_company.name,
"dest_company_id": dest_company.id,
}
)
# Use test.Form() class to trigger propper onchanges on the invoice
dest_invoice_data = Form(
self.env["account.move"]
.with_company(dest_company.id)
.with_context(
default_move_type=dest_inv_type,
)
)
dest_invoice_data.journal_id = dest_journal
dest_invoice_data.partner_id = self.company_id.partner_id
dest_invoice_data.ref = self.name
dest_invoice_data.invoice_date = self.invoice_date
dest_invoice_data.narration = self.narration
dest_invoice_data.currency_id = self.currency_id
vals = dest_invoice_data._values_to_save(all_fields=True)
vals.update(
{
"invoice_origin": _("%(company_name)s - Invoice: %(invoice_name)s")
% {"company_name": self.company_id.name, "invoice_name": self.name},
"auto_invoice_id": self.id,
"auto_generated": True,
}
)
# CHECK ME: This field is created by module sale, maybe we need add dependency?
if (
hasattr(self, "partner_shipping_id")
and self.partner_shipping_id
and not self.partner_shipping_id.company_id
):
# if shipping partner is shared you may want to propagate its value
# to supplier invoice allowing to analyse invoices
vals["partner_shipping_id"] = self.partner_shipping_id.id
return vals
def button_draft(self):
for move in self:
inter_invoice_posted = self.sudo().search(
[("auto_invoice_id", "=", move.id), ("state", "=", "posted")], limit=1
)
if inter_invoice_posted:
raise UserError(
_(
"You can't modify this invoice as it has an inter company "
"invoice that's in posted state.\n"
"Invoice %(invoice_name)s to %(partner_name)s"
)
% {
"invoice_name": inter_invoice_posted.name,
"partner_name": inter_invoice_posted.partner_id.display_name,
}
)
return super().button_draft()
def button_cancel(self):
for invoice in self:
company = invoice._find_company_from_invoice_partner()
if company and not invoice.auto_generated:
for inter_invoice in self.sudo().search(
[("auto_invoice_id", "=", invoice.id)]
):
inter_invoice.button_draft()
inter_invoice.write(
{
"invoice_origin": _(
"%(company_name)s - Canceled Invoice: %(invoice_name)s"
)
% {
"company_name": invoice.company_id.name,
"invoice_name": invoice.name,
}
}
)
inter_invoice.button_cancel()
return super().button_cancel()
def write(self, vals):
res = super().write(vals)
if self.env.context.get("skip_check_amount_difference"):
return res
for move in self.filtered("auto_invoice_id"):
if (
float_compare(
move.amount_untaxed,
move.sudo().auto_invoice_id.amount_untaxed,
precision_rounding=move.currency_id.rounding,
)
!= 0
):
raise UserError(
_(
"This is an autogenerated multi company invoice and you're "
"trying to modify the amount, which will differ from the "
"source one (%s)"
)
% (move.sudo().auto_invoice_id.name)
)
return res
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
auto_invoice_line_id = fields.Many2one(
"account.move.line",
string="Source Invoice Line",
readonly=True,
copy=False,
prefetch=False,
)
@api.model
def _prepare_account_move_line(self, dest_move, dest_company):
"""Generate invoice line values
:param dest_move : the created invoice
:rtype dest_move : account.move record
:param dest_company : the company of the created invoice
:rtype dest_company : res.company record
"""
self.ensure_one()
# Use test.Form() class to trigger propper onchanges on the line
product = self.product_id or False
dest_form = Form(
dest_move.with_company(dest_company.id),
"account_invoice_inter_company.view_move_form",
)
with dest_form.invoice_line_ids.new() as line_form:
# HACK: Related fields manually set due to Form() limitations
line_form.company_id = dest_move.company_id
# Regular fields
line_form.display_type = self.display_type
line_form.product_id = product
line_form.name = self.name
if line_form.product_uom_id != self.product_uom_id:
line_form.product_uom_id = self.product_uom_id
line_form.quantity = self.quantity
# TODO: it's wrong to just copy the price_unit
# You have to check if the tax is price_include True or False
# in source and target companies
line_form.price_unit = self.price_unit
line_form.discount = self.discount
line_form.sequence = self.sequence
vals = dest_form._values_to_save(all_fields=True)["invoice_line_ids"][0][2]
vals.update({"move_id": dest_move.id, "auto_invoice_line_id": self.id})
if self.analytic_account_id and not self.analytic_account_id.company_id:
vals["analytic_account_id"] = self.analytic_account_id.id
analytic_tags = self.analytic_tag_ids.filtered(lambda x: not x.company_id)
if analytic_tags:
vals["analytic_tag_ids"] = [(4, x) for x in analytic_tags.ids]
return vals
| 41.850704 | 14,857 |
1,288 |
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResCompany(models.Model):
_inherit = "res.company"
company_share_product = fields.Boolean(
"Share product to all companies",
compute="_compute_share_product",
compute_sudo=True,
)
invoice_auto_validation = fields.Boolean(
help="When an invoice is created by a multi company rule "
"for this company, it will automatically validate it",
default=True,
)
intercompany_invoice_user_id = fields.Many2one(
"res.users",
string="Inter Company Invoice User",
help="Responsible user for creation of invoices triggered by "
"intercompany rules.",
)
def _compute_share_product(self):
product_rule = self.env.ref("product.product_comp_rule")
for company in self:
company.company_share_product = not bool(product_rule.active)
def _get_user_domain(self):
self.ensure_one()
group_account_invoice = self.env.ref("account.group_account_invoice")
return [
("id", "!=", self.env.ref("base.user_root").id),
("company_ids", "=", self.id),
("id", "in", group_account_invoice.users.ids),
]
| 33.025641 | 1,288 |
1,765 |
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
invoice_auto_validation = fields.Boolean(
related="company_id.invoice_auto_validation",
string="Invoices Auto Validation",
readonly=False,
help="When an invoice is created by a multi company rule for "
"this company, it will automatically validate it.",
)
intercompany_invoice_user_id = fields.Many2one(
related="company_id.intercompany_invoice_user_id",
readonly=False,
help="Responsible user for creation of invoices triggered by "
"intercompany rules. If not set the user initiating the"
"transaction will be used",
)
company_share_product = fields.Boolean(
"Share product to all companies",
help="Share your product to all companies defined in your instance.\n"
" * Checked : Product are visible for every company, "
"even if a company is defined on the partner.\n"
" * Unchecked : Each company can see only its product "
"(product where company is defined). Product not related to a "
"company are visible for all companies.",
)
@api.model
def get_values(self):
res = super().get_values()
product_rule = self.env.ref("product.product_comp_rule")
res.update(
company_share_product=not bool(product_rule.active),
)
return res
def set_values(self):
res = super().set_values()
product_rule = self.env.ref("product.product_comp_rule")
product_rule.write({"active": not bool(self.company_share_product)})
return res
| 37.553191 | 1,765 |
562 |
py
|
PYTHON
|
15.0
|
# Copyright 2021 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Stock Intercompany Delivery-Reception",
"Summary": "Module that adds possibility for intercompany Delivery-Reception",
"version": "15.0.1.1.1",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/multi-company",
"category": "Warehouse Management",
"depends": ["stock"],
"installable": True,
"license": "AGPL-3",
"data": [
"views/res_config_settings.xml",
],
}
| 33.058824 | 562 |
4,496 |
py
|
PYTHON
|
15.0
|
# Copyright 2021 Camptocamp
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import RecordCapturer, TransactionCase
class TestIntercompanyDelivery(TransactionCase):
def setUp(self):
super().setUp()
self.user_demo = self.env["res.users"].create(
{
"login": "firstnametest",
"name": "User Demo",
"email": "[email protected]",
"groups_id": [
(4, self.env.ref("base.group_user").id),
(4, self.env.ref("stock.group_stock_user").id),
],
}
)
company_obj = self.env["res.company"]
# Create 2 companies and configure intercompany picking type param on them
self.company1 = company_obj.create({"name": "Company A"})
self.company2 = company_obj.create({"name": "Company B"})
self.picking_type_1 = (
self.env["stock.picking.type"]
.sudo()
.search(
[
("company_id", "=", self.company1.id),
("name", "=", "Delivery Orders"),
],
limit=1,
)
)
self.picking_type_2 = (
self.env["stock.picking.type"]
.sudo()
.search(
[("company_id", "=", self.company2.id), ("name", "=", "Receipts")],
limit=1,
)
)
self.company1.intercompany_in_type_id = self.picking_type_1.id
self.company2.intercompany_in_type_id = self.picking_type_2.id
# assign both companies to current user
self.user_demo.write(
{
"company_id": self.company1.id,
"company_ids": [(4, self.company1.id), (4, self.company2.id)],
}
)
# create storable product
self.product1 = self.env["product.product"].create(
{
"name": "Product A",
"type": "product",
"categ_id": self.env.ref("product.product_category_all").id,
"qty_available": 100,
}
)
self.stock_location = (
self.env["stock.location"]
.sudo()
.search([("name", "=", "Stock"), ("company_id", "=", self.company1.id)])
)
self.uom_unit = self.env.ref("uom.product_uom_unit")
def test_picking_creation(self):
stock_location = self.env["stock.location"].search(
[("usage", "=", "internal"), ("company_id", "=", self.company1.id)]
)
custs_location = self.env.ref("stock.stock_location_customers")
custs_location.company_id = False
self.product1.company_id = False
picking = (
self.env["stock.picking"]
.with_context(default_company_id=self.company1.id)
.with_user(self.user_demo)
.create(
{
"partner_id": self.company2.partner_id.id,
"location_id": stock_location.id,
"location_dest_id": custs_location.id,
"picking_type_id": self.company1.intercompany_in_type_id.id,
}
)
)
self.env["stock.move.line"].create(
{
"location_id": stock_location.id,
"location_dest_id": custs_location.id,
"product_id": self.product1.id,
"product_uom_id": self.uom_unit.id,
"qty_done": 1.0,
"picking_id": picking.id,
}
)
with RecordCapturer(self.env["stock.picking"], []) as rc:
picking.action_confirm()
picking.button_validate()
counterpart_picking = rc.records
self.assertEqual(len(counterpart_picking), 1)
self.assertEqual(counterpart_picking.counterpart_of_picking_id, picking)
self.assertEqual(len(counterpart_picking.move_lines), len(picking.move_lines))
for cp_move, move in zip(counterpart_picking.move_lines, picking.move_lines):
self.assertEqual(cp_move.counterpart_of_move_id, move)
self.assertEqual(
len(counterpart_picking.move_line_ids), len(picking.move_line_ids)
)
for cp_line, line in zip(
counterpart_picking.move_line_ids, picking.move_line_ids
):
self.assertEqual(cp_line.counterpart_of_line_id, line)
| 38.758621 | 4,496 |
188 |
py
|
PYTHON
|
15.0
|
from odoo import fields, models
class StockMoveLine(models.Model):
_inherit = "stock.move.line"
counterpart_of_line_id = fields.Many2one("stock.move.line", check_company=False)
| 26.857143 | 188 |
174 |
py
|
PYTHON
|
15.0
|
from odoo import fields, models
class StockMove(models.Model):
_inherit = "stock.move"
counterpart_of_move_id = fields.Many2one("stock.move", check_company=False)
| 24.857143 | 174 |
216 |
py
|
PYTHON
|
15.0
|
from odoo import fields, models
class ResCompany(models.Model):
_inherit = "res.company"
intercompany_in_type_id = fields.Many2one(
"stock.picking.type", string="Intercompany operation type"
)
| 24 | 216 |
3,478 |
py
|
PYTHON
|
15.0
|
from odoo import fields, models
class StockPicking(models.Model):
_inherit = "stock.picking"
counterpart_of_picking_id = fields.Many2one("stock.picking", check_company=False)
def _create_counterpart_picking(self):
companies = self.env["res.company"].sudo().search([])
partners = {cp.partner_id: cp for cp in companies}
picking = self.env["stock.picking"]
if self.partner_id in partners:
company = partners[self.partner_id]
vals = self._get_counterpart_picking_vals(company)
new_picking_vals = self.sudo().copy_data(default=vals)
picking = (
self.env["stock.picking"]
.sudo()
.with_company(company)
.create(new_picking_vals)
)
picking.action_confirm()
return picking
def _get_counterpart_picking_vals(self, company):
if company.intercompany_in_type_id.warehouse_id:
warehouse = company.intercompany_in_type_id.warehouse_id
else:
warehouse = (
self.env["stock.warehouse"]
.sudo()
.search([("company_id", "=", company.id)], limit=1)
)
ptype = company.intercompany_in_type_id or warehouse.in_type_id
move_lines, move_line_ids = self._check_company_consistency(company)
return {
"partner_id": self.env.user.company_id.partner_id.id,
"company_id": company.id,
"origin": self.name,
"picking_type_id": ptype.id,
"state": "draft",
"location_id": self.env.ref("stock.stock_location_suppliers").id,
"location_dest_id": warehouse.lot_stock_id.id,
"counterpart_of_picking_id": self.id,
"move_lines": move_lines,
"move_line_ids": move_line_ids,
}
def _check_company_consistency(self, company):
# Replace company_id by the right one to create the counterpart picking
common_vals = {
"company_id": company.id,
"location_id": self.env.ref("stock.stock_location_suppliers").id,
}
move_lines = [
(
0,
0,
sm.with_company(company).copy_data(
dict(common_vals, counterpart_of_move_id=sm.id)
)[0],
)
for sm in self.move_lines
]
move_line_ids = [
(
0,
0,
ln.with_company(company).copy_data(
dict(common_vals, move_id=False, counterpart_of_line_id=ln.id)
)[0],
)
for ln in self.move_line_ids
]
return move_lines, move_line_ids
# override of method from stock module
def _action_done(self):
counterparts = []
for picking in self:
if picking.location_dest_id.usage == "customer":
counterpart = picking._create_counterpart_picking()
counterparts.append((picking, counterpart))
res = super(StockPicking, self)._action_done()
for picking, counterpart in counterparts:
picking._finalize_counterpart_picking(counterpart)
return res
def _finalize_counterpart_picking(self, counterpart_picking):
"""hook to finalize required steps on the counterpart picking after the initial
outgoing picking is done"""
| 37.804348 | 3,478 |
343 |
py
|
PYTHON
|
15.0
|
# Copyright 2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
intercompany_in_type_id = fields.Many2one(
related="company_id.intercompany_in_type_id", readonly=False
)
| 28.583333 | 343 |
642 |
py
|
PYTHON
|
15.0
|
# Copyright 2018 Carlos Dauden - Tecnativa <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Quick Company Creation Wizard",
"summary": "This module adds a wizard to create companies easily",
"version": "15.0.1.0.0",
"category": "Multicompany",
"website": "https://github.com/OCA/multi-company"
"account_multicompany_easy_creation",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["account"],
"data": ["wizards/multicompany_easy_creation.xml", "security/ir.model.access.csv"],
}
| 42.8 | 642 |
2,580 |
py
|
PYTHON
|
15.0
|
# Copyright 2021-2022 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo.tests import Form, common, new_test_user
from odoo.tests.common import users
class TestEasyCreation(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env.ref("base.user_admin").write(
{
"groups_id": [(4, cls.env.ref("account.group_account_user").id)],
}
)
new_test_user(
cls.env,
login="test-user",
groups="account.group_account_user,base.group_system,base.group_partner_manager",
)
cls.chart_template_id = cls.env["account.chart.template"].search([], limit=1)
cls.sale_tax_template = cls.env["account.tax.template"].search(
[("type_tax_use", "=", "sale")], limit=1
)
cls.purchase_tax_template = cls.env["account.tax.template"].search(
[("type_tax_use", "=", "purchase")], limit=1
)
def _test_model_items(self, model, company_id):
self.assertGreaterEqual(
self.env[model].search_count([("company_id", "=", company_id.id)]), 1
)
def test_wizard_easy_creation(self):
wizard_form = Form(
self.env["account.multicompany.easy.creation.wiz"].with_context(
allowed_company_ids=self.env.company.ids
)
)
wizard_form.name = "test_company"
wizard_form.default_purchase_tax_id = self.purchase_tax_template
wizard_form.chart_template_id = self.chart_template_id
wizard_form.update_default_taxes = True
wizard_form.smart_search_product_tax = True
wizard_form.force_sale_tax = True
wizard_form.force_purchase_tax = True
wizard_form.default_sale_tax_id = self.sale_tax_template
for user in self.env["res.users"].search([]):
wizard_form.user_ids.add(user)
record = wizard_form.save()
record.action_accept()
self.assertEqual(record.new_company_id.name, "test_company")
self.assertEqual(
record.new_company_id.chart_template_id, self.chart_template_id
)
# Some misc validations
self._test_model_items("account.tax", record.new_company_id)
self._test_model_items("account.account", record.new_company_id)
self._test_model_items("account.journal", record.new_company_id)
@users("test-user")
def test_wizard_easy_creation_test_user(self):
self.test_wizard_easy_creation()
| 40.28125 | 2,578 |
15,355 |
py
|
PYTHON
|
15.0
|
# Copyright 2018 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import ormcache
from odoo.tools.safe_eval import safe_eval
class AccountMulticompanyEasyCreationWiz(models.TransientModel):
_name = "account.multicompany.easy.creation.wiz"
_description = "Wizard Account Multi-company Easy Creation"
def _default_sequence_ids(self):
# this is a "trick" for avoiding glue modules
exclude_seq_list = self.env["ir.config_parameter"].get_param(
"account_multicompany_easy_creation.exclude_sequence_list",
[
False,
"aeat.sequence.type",
"pos.config.simplified_invoice",
"stock.scrap",
],
)
if not isinstance(exclude_seq_list, list):
exclude_seq_list = safe_eval(exclude_seq_list)
return self.env["ir.sequence"].search(
[
("company_id", "=", self.env.user.company_id.id),
("code", "not in", exclude_seq_list),
]
)
name = fields.Char(
string="Company Name",
required=True,
)
currency_id = fields.Many2one(
comodel_name="res.currency",
string="Currency",
required=True,
default=lambda s: s.env.user.company_id.currency_id,
)
chart_template_id = fields.Many2one(
comodel_name="account.chart.template",
string="Chart Template",
)
bank_ids = fields.One2many(
comodel_name="account.multicompany.bank.wiz",
inverse_name="wizard_id",
string="Bank accounts to create",
)
user_ids = fields.Many2many(
comodel_name="res.users",
string="Users allowed",
domain=[("share", "=", False)],
)
sequence_ids = fields.Many2many(
comodel_name="ir.sequence",
string="Sequences to create",
default=lambda s: s._default_sequence_ids(),
)
new_company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
)
# TAXES
smart_search_product_tax = fields.Boolean(
default=True,
help="Go over product taxes in actual company to match and set "
"equivalent taxes in then new company.",
)
update_default_taxes = fields.Boolean(
help="Update default taxes applied to local transactions",
)
default_sale_tax_id = fields.Many2one(
comodel_name="account.tax.template",
string="Default Sales Tax",
)
force_sale_tax = fields.Boolean(
string="Force Sale Tax In All Products",
help="Set default sales tax to all products.\n"
"If smart search product tax is also enabled matches founded "
"will overwrite default taxes, but not founded will remain",
)
default_purchase_tax_id = fields.Many2one(
comodel_name="account.tax.template",
string="Default Purchase Tax",
)
force_purchase_tax = fields.Boolean(
string="Force Purchase Tax In All Products",
help="Set default purchase tax to all products.\n"
"If smart search product tax is also enabled matches founded "
"will overwrite default taxes, but not founded will remain",
)
# ACCOUNTS
smart_search_specific_account = fields.Boolean(
default=True,
help="Go over specific accounts in actual company to match and set "
"equivalent taxes in the new company.\n"
"Applies to products, categories, partners, ...",
)
smart_search_fiscal_position = fields.Boolean(
default=True,
help="Go over partner fiscal positions in actual company to match "
"and set equivalent fiscal positions in the new company.",
)
update_default_accounts = fields.Boolean(
help="Update default accounts defined in account chart template",
)
account_receivable_id = fields.Many2one(
comodel_name="account.account.template",
string="Default Receivable Account",
)
account_payable_id = fields.Many2one(
comodel_name="account.account.template",
string="Default Payable Account",
)
account_income_categ_id = fields.Many2one(
comodel_name="account.account.template",
string="Default Category Income Account",
)
account_expense_categ_id = fields.Many2one(
comodel_name="account.account.template",
string="Default Category Expense Account",
)
def create_bank_journals(self):
AccountJournal = self.env["account.journal"].sudo()
AccountAccount = self.env["account.account"].sudo()
bank_journals = AccountJournal.search(
[("type", "=", "bank"), ("company_id", "=", self.new_company_id.id)]
)
vals = {
"type": "bank",
"company_id": self.new_company_id.id,
}
for i, bank in enumerate(self.bank_ids):
vals.update({"name": bank.acc_number, "bank_acc_number": bank.acc_number})
if i < len(bank_journals):
bank_journals[i].update(vals)
else:
account_account = AccountAccount.create(
{
"code": "57200X",
"name": vals["name"],
"user_type_id": self.env.ref(
"account.data_account_type_liquidity"
).id,
"company_id": vals["company_id"],
}
)
vals.update(
{
"code": False,
"sequence_id": False,
"default_debit_account_id": account_account.id,
"default_credit_account_id": account_account.id,
}
)
AccountJournal.create(vals)
def create_sequences(self):
for sequence in self.sudo().sequence_ids:
sequence.copy({"company_id": self.new_company_id.id})
def create_company(self):
self.new_company_id = self.env["res.company"].create(
{"name": self.name, "user_ids": [(6, 0, self.user_ids.ids)]}
)
allowed_company_ids = (
self.env.context.get("allowed_company_ids", []) + self.new_company_id.ids
)
new_company = self.new_company_id.with_context(
allowed_company_ids=allowed_company_ids
)
self.with_context(
allowed_company_ids=allowed_company_ids
).chart_template_id.try_loading(company=new_company)
self.create_bank_journals()
self.create_sequences()
@ormcache("self.id", "company_id", "match_taxes")
def taxes_by_company(self, company_id, match_taxes):
xml_ids = match_taxes.sudo().get_external_id().values()
# If any tax doesn't have xml, we won't be able to match it
record_ids = []
for xml_id in xml_ids:
if not xml_id:
continue
module, ref = xml_id.split(".", 1)
_company, name = ref.split("_", 1)
record = self.env.ref("{}.{}_{}".format(module, company_id, name), False)
if record:
record_ids.append(record.id)
return record_ids
def update_product_taxes(self, product, taxes_field, company_from):
product_taxes = product[taxes_field].filtered(
lambda tax: tax.company_id == company_from
)
tax_ids = product_taxes and self.taxes_by_company(
self.new_company_id.id, product_taxes
)
if tax_ids:
product.update({taxes_field: [(4, tax_id) for tax_id in tax_ids]})
return True
return False
def match_tax(self, tax_template):
"""We can only match the new company tax if the chart was used"""
xml_id = tax_template and tax_template.get_external_id().get(tax_template.id)
if not xml_id:
raise ValidationError(
_("This tax template can't be match without xml_id: '%s'")
% tax_template.name
)
module, name = xml_id.split(".", 1)
return self.sudo().env.ref(
"{}.{}_{}".format(module, self.new_company_id.id, name)
)
def set_product_taxes(self):
user_company = self.env.user.company_id
products = (
self.env["product.product"]
.sudo()
.search(
[
"&",
("company_id", "=", False),
"|",
("taxes_id", "!=", False),
("supplier_taxes_id", "!=", False),
]
)
)
updated_sale = updated_purchase = products.browse()
if self.smart_search_product_tax:
for product in products.filtered("taxes_id"):
if self.update_product_taxes(product, "taxes_id", user_company):
updated_sale |= product
if self.update_default_taxes and self.force_sale_tax:
(products - updated_sale).update(
{"taxes_id": [(4, self.match_tax(self.default_sale_tax_id).id)]}
)
if self.smart_search_product_tax:
for product in products.filtered("supplier_taxes_id"):
if self.update_product_taxes(
product, "supplier_taxes_id", user_company
):
updated_purchase |= product
if self.update_default_taxes and self.force_purchase_tax:
(products - updated_purchase).update(
{
"supplier_taxes_id": [
(4, self.match_tax(self.default_purchase_tax_id).id)
],
}
)
def update_taxes(self):
if self.update_default_taxes:
IrDefault = self.env["ir.default"].sudo()
if self.default_sale_tax_id:
IrDefault.set(
model_name="product.template",
field_name="taxes_id",
value=self.match_tax(self.default_sale_tax_id).ids,
company_id=self.new_company_id.id,
)
if self.default_purchase_tax_id:
IrDefault.set(
model_name="product.template",
field_name="supplier_taxes_id",
value=self.match_tax(self.default_purchase_tax_id).ids,
company_id=self.new_company_id.id,
)
self.set_product_taxes()
def set_specific_properties(self, model, match_field):
user_company = self.env.user.company_id
self_sudo = self.sudo()
new_company_id = self.new_company_id.id
IrProperty = self_sudo.env["ir.property"]
properties = IrProperty.search(
[
("company_id", "=", user_company.id),
("type", "=", "many2one"),
("res_id", "!=", False),
("value_reference", "=like", "{},%".format(model)),
]
)
Model = self_sudo.env[model]
for prop in properties:
ref = Model.browse(int(prop.value_reference.split(",")[1]))
new_ref = Model.search(
[
("company_id", "=", new_company_id),
(match_field, "=", ref[match_field]),
]
)
if new_ref:
prop.copy(
{
"company_id": new_company_id,
"value_reference": "{},{}".format(model, new_ref.id),
"value_float": False,
"value_integer": False,
}
)
def match_account(self, account_template):
return (
self.sudo()
.env["account.account"]
.search(
[
("company_id", "=", self.new_company_id.id),
("code", "=", account_template.code),
],
limit=1,
)
)
def set_global_properties(self):
IrProperty = self.env["ir.property"].sudo()
todo_list = [
(
"property_account_receivable_id",
"res.partner",
"account.account",
self.match_account(self.account_receivable_id).id,
),
(
"property_account_payable_id",
"res.partner",
"account.account",
self.match_account(self.account_payable_id).id,
),
(
"property_account_expense_categ_id",
"product.category",
"account.account",
self.match_account(self.account_expense_categ_id).id,
),
(
"property_account_income_categ_id",
"product.category",
"account.account",
self.match_account(self.account_income_categ_id).id,
),
]
new_company = self.new_company_id
for record in todo_list:
if not record[3]:
continue
field = self.env["ir.model.fields"].search(
[
("name", "=", record[0]),
("model", "=", record[1]),
("relation", "=", record[2]),
],
limit=1,
)
vals = {
"name": record[0],
"company_id": new_company.id,
"fields_id": field.id,
"value": "{},{}".format(record[2], record[3]),
}
properties = IrProperty.search(
[("name", "=", record[0]), ("company_id", "=", new_company.id)]
)
if properties:
properties.write(vals)
else:
IrProperty.create(vals)
def update_properties(self):
if self.smart_search_specific_account:
self.set_specific_properties("account.account", "code")
if self.smart_search_fiscal_position:
self.set_specific_properties("account.fiscal.position", "name")
if self.update_default_accounts:
self.set_global_properties()
def action_res_company_form(self):
action = self.env["ir.actions.act_window"]._for_xml_id(
"base.action_res_company_form"
)
form = self.env.ref("base.view_company_form")
action["views"] = [(form.id, "form")]
action["res_id"] = self.new_company_id.id
return action
def action_accept(self):
self.create_company()
self.update_taxes()
self.update_properties()
return self.action_res_company_form()
class AccountMulticompanyBankWiz(models.TransientModel):
_inherit = "res.partner.bank"
_name = "account.multicompany.bank.wiz"
_order = "id"
_description = "Wizard Account Multi-company Bank"
wizard_id = fields.Many2one(
comodel_name="account.multicompany.easy.creation.wiz",
)
partner_id = fields.Many2one(
required=False,
)
| 37 | 15,355 |
669 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Inter Company Module for Purchase to Sale Order",
"summary": "Intercompany PO/SO rules",
"version": "15.0.1.0.0",
"category": "Purchase Management",
"website": "https://github.com/OCA/multi-company",
"author": "Odoo SA, Akretion, Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["sale", "purchase", "account_invoice_inter_company"],
"data": ["views/res_config_view.xml"],
}
| 39.352941 | 669 |
6,696 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2019-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import UserError
from odoo.tests.common import Form
from odoo.addons.account_invoice_inter_company.tests.test_inter_company_invoice import (
TestAccountInvoiceInterCompanyBase,
)
class TestPurchaseSaleInterCompany(TestAccountInvoiceInterCompanyBase):
@classmethod
def _configure_user(cls, user):
for xml in [
"account.group_account_manager",
"base.group_partner_manager",
"sales_team.group_sale_manager",
"purchase.group_purchase_manager",
]:
user.groups_id |= cls.env.ref(xml)
@classmethod
def _create_purchase_order(cls, partner):
po = Form(cls.env["purchase.order"])
po.company_id = cls.company_a
po.partner_id = partner
cls.product.invoice_policy = "order"
with po.order_line.new() as line_form:
line_form.product_id = cls.product
line_form.product_qty = 3.0
line_form.name = "Service Multi Company"
line_form.price_unit = 450.0
return po.save()
@classmethod
def setUpClass(cls):
super().setUpClass()
# no job: avoid issue if account_invoice_inter_company_queued is installed
cls.env = cls.env(context={"test_queue_job_no_delay": 1})
cls.product = cls.product_consultant_multi_company
if "company_ids" in cls.env["res.partner"]._fields:
# We have to do that because the default method added a company
cls.partner_company_a.company_ids = [(6, 0, cls.company_a.ids)]
cls.partner_company_b.company_ids = [(6, 0, cls.company_b.ids)]
# Configure Company B (the supplier)
cls.company_b.so_from_po = True
cls.company_b.sale_auto_validation = 1
cls.intercompany_sale_user_id = cls.user_company_b.copy()
cls.intercompany_sale_user_id.company_ids |= cls.company_a
cls.company_b.intercompany_sale_user_id = cls.intercompany_sale_user_id
# Configure User
cls._configure_user(cls.user_company_a)
cls._configure_user(cls.user_company_b)
# Create purchase order
cls.purchase_company_a = cls._create_purchase_order(cls.partner_company_b)
# Configure pricelist to USD
cls.env["product.pricelist"].sudo().search([]).write(
{"currency_id": cls.env.ref("base.USD").id}
)
def _approve_po(self):
"""Confirm the PO in company A and return the related sale of Company B"""
self.purchase_company_a.with_user(self.user_company_a).button_approve()
return (
self.env["sale.order"]
.with_user(self.user_company_b)
.search([("auto_purchase_order_id", "=", self.purchase_company_a.id)])
)
def test_purchase_sale_inter_company(self):
self.purchase_company_a.notes = "Test note"
sale = self._approve_po()
self.assertEqual(len(sale), 1)
self.assertEqual(sale.state, "sale")
self.assertEqual(sale.partner_id, self.partner_company_a)
self.assertEqual(len(sale.order_line), len(self.purchase_company_a.order_line))
self.assertEqual(sale.order_line.product_id, self.product)
self.assertEqual(str(sale.note), "<p>Test note</p>")
def test_not_auto_validate(self):
self.company_b.sale_auto_validation = False
sale = self._approve_po()
self.assertEqual(sale.state, "draft")
# TODO FIXME
def xxtest_date_planned(self):
# Install sale_order_dates module
module = self.env["ir.module.module"].search(
[("name", "=", "sale_order_dates")]
)
if not module:
return False
module.button_install()
self.purchase_company_a.date_planned = "2070-12-31"
sale = self._approve_po()
self.assertEqual(sale.requested_date, "2070-12-31")
def test_raise_product_access(self):
product_rule = self.env.ref("product.product_comp_rule")
product_rule.active = True
# if product_multi_company is installed
if "company_ids" in self.env["product.template"]._fields:
self.product.company_ids = [(6, 0, [self.company_a.id])]
self.product.company_id = self.company_a
with self.assertRaises(UserError):
self._approve_po()
def test_raise_currency(self):
currency = self.env.ref("base.EUR")
self.purchase_company_a.currency_id = currency
with self.assertRaises(UserError):
self._approve_po()
def test_purchase_invoice_relation(self):
self.partner_company_a.company_id = False
self.partner_company_b.company_id = False
sale = self._approve_po()
sale_invoice = sale._create_invoices()[0]
sale_invoice.action_post()
self.assertEqual(len(self.purchase_company_a.invoice_ids), 1)
self.assertEqual(
self.purchase_company_a.invoice_ids.auto_invoice_id,
sale_invoice,
)
self.assertEqual(len(self.purchase_company_a.order_line.invoice_lines), 1)
self.assertEqual(self.purchase_company_a.order_line.qty_invoiced, 3)
def test_cancel(self):
self.company_b.sale_auto_validation = False
sale = self._approve_po()
self.assertEqual(self.purchase_company_a.partner_ref, sale.name)
self.purchase_company_a.with_user(self.user_company_a).button_cancel()
self.assertFalse(self.purchase_company_a.partner_ref)
self.assertEqual(sale.state, "cancel")
def test_cancel_confirmed_po_so(self):
self.company_b.sale_auto_validation = True
self._approve_po()
with self.assertRaises(UserError):
self.purchase_company_a.with_user(self.user_company_a).button_cancel()
def test_so_change_price(self):
sale = self._approve_po()
sale.order_line.price_unit = 10
sale.action_confirm()
self.assertEqual(self.purchase_company_a.order_line.price_unit, 10)
def test_po_with_contact_as_partner(self):
contact = self.env["res.partner"].create(
{"name": "Test contact", "parent_id": self.partner_company_b.id}
)
self.purchase_company_a = self._create_purchase_order(contact)
sale = self._approve_po()
self.assertEqual(len(sale), 1)
self.assertEqual(sale.state, "sale")
self.assertEqual(sale.partner_id, self.partner_company_a)
| 39.621302 | 6,696 |
1,232 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, models
class AccountMove(models.Model):
_inherit = "account.move"
def _inter_company_create_invoice(self, dest_company):
res = super()._inter_company_create_invoice(dest_company)
if res["dest_invoice"].move_type == "in_invoice":
self._link_invoice_purchase(res["dest_invoice"])
return res
def _link_invoice_purchase(self, dest_invoice):
self.ensure_one()
orders = self.env["purchase.order"]
for line in dest_invoice.invoice_line_ids:
line.purchase_line_id = (
line.auto_invoice_line_id.sale_line_ids.auto_purchase_line_id
)
orders = dest_invoice.invoice_line_ids.purchase_line_id.order_id
if orders:
ref = "<a href=# data-oe-model=purchase.order data-oe-id={}>{}</a>"
message = _("This vendor bill is related with: {}").format(
",".join([ref.format(o.id, o.name) for o in orders])
)
dest_invoice.message_post(body=message)
| 39.741935 | 1,232 |
1,020 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class SaleOrder(models.Model):
_inherit = "sale.order"
auto_purchase_order_id = fields.Many2one(
comodel_name="purchase.order",
string="Source Purchase Order",
readonly=True,
copy=False,
)
def action_confirm(self):
for order in self.filtered("auto_purchase_order_id"):
for line in order.order_line.sudo():
if line.auto_purchase_line_id:
line.auto_purchase_line_id.price_unit = line.price_unit
return super().action_confirm()
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
auto_purchase_line_id = fields.Many2one(
comodel_name="purchase.order.line",
string="Source Purchase Order Line",
readonly=True,
copy=False,
)
| 29.142857 | 1,020 |
7,504 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, models
from odoo.exceptions import UserError
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
def button_approve(self, force=False):
"""Generate inter company sale order base on conditions."""
res = super().button_approve(force)
for purchase_order in self.sudo():
# get the company from partner then trigger action of
# intercompany relation
dest_company = (
purchase_order.partner_id.commercial_partner_id.ref_company_ids
)
if dest_company and dest_company.so_from_po:
purchase_order.with_company(
dest_company.id
)._inter_company_create_sale_order(dest_company)
return res
def _get_user_domain(self, dest_company):
self.ensure_one()
group_purchase_user = self.env.ref("purchase.group_purchase_user")
return [
("id", "!=", 1),
("company_id", "=", dest_company.id),
("id", "in", group_purchase_user.users.ids),
]
def _check_intercompany_product(self, dest_company):
domain = self._get_user_domain(dest_company)
dest_user = self.env["res.users"].search(domain, limit=1)
if dest_user:
for purchase_line in self.order_line:
if (
purchase_line.product_id.company_id
and purchase_line.product_id.company_id not in dest_user.company_ids
):
raise UserError(
_(
"You cannot create SO from PO because product '%s' "
"is not intercompany"
)
% purchase_line.product_id.name
)
def _inter_company_create_sale_order(self, dest_company):
"""Create a Sale Order from the current PO (self)
Note : In this method, reading the current PO is done as sudo,
and the creation of the derived
SO as intercompany_user, minimizing the access right required
for the trigger user.
:param dest_company : the company of the created PO
:rtype dest_company : res.company record
"""
self.ensure_one()
# Check intercompany user
intercompany_user = dest_company.intercompany_sale_user_id
if not intercompany_user:
intercompany_user = self.env.user
# check intercompany product
self._check_intercompany_product(dest_company)
# Accessing to selling partner with selling user, so data like
# property_account_position can be retrieved
company_partner = self.company_id.partner_id
# check pricelist currency should be same with PO/SO document
if self.currency_id.id != (
company_partner.property_product_pricelist.currency_id.id
):
raise UserError(
_(
"You cannot create SO from PO because "
"sale price list currency is different than "
"purchase price list currency."
)
)
# create the SO and generate its lines from the PO lines
sale_order_data = self._prepare_sale_order_data(
self.name, company_partner, dest_company, self.dest_address_id
)
sale_order = (
self.env["sale.order"]
.with_user(intercompany_user.id)
.sudo()
.create(sale_order_data)
)
for purchase_line in self.order_line:
sale_line_data = self._prepare_sale_order_line_data(
purchase_line, dest_company, sale_order
)
self.env["sale.order.line"].with_user(intercompany_user.id).sudo().create(
sale_line_data
)
# write supplier reference field on PO
if not self.partner_ref:
self.partner_ref = sale_order.name
# Validation of sale order
if dest_company.sale_auto_validation:
sale_order.with_user(intercompany_user.id).sudo().action_confirm()
def _prepare_sale_order_data(
self, name, partner, dest_company, direct_delivery_address
):
"""Generate the Sale Order values from the PO
:param name : the origin client reference
:rtype name : string
:param partner : the partner reprenseting the company
:rtype partner : res.partner record
:param dest_company : the company of the created SO
:rtype dest_company : res.company record
:param direct_delivery_address : the address of the SO
:rtype direct_delivery_address : res.partner record
"""
self.ensure_one()
delivery_address = direct_delivery_address or partner or False
new_order = self.env["sale.order"].new(
{
"company_id": dest_company.id,
"client_order_ref": name,
"partner_id": partner.id,
"date_order": self.date_approve,
"auto_purchase_order_id": self.id,
}
)
for onchange_method in new_order._onchange_methods["partner_id"]:
onchange_method(new_order)
new_order.user_id = False
if delivery_address:
new_order.partner_shipping_id = delivery_address
if self.notes:
new_order.note = self.notes
new_order.commitment_date = self.date_planned
return new_order._convert_to_write(new_order._cache)
def _prepare_sale_order_line_data(self, purchase_line, dest_company, sale_order):
"""Generate the Sale Order Line values from the PO line
:param purchase_line : the origin Purchase Order Line
:rtype purchase_line : purchase.order.line record
:param dest_company : the company of the created SO
:rtype dest_company : res.company record
:param sale_order : the Sale Order
"""
new_line = self.env["sale.order.line"].new(
{
"order_id": sale_order.id,
"product_id": purchase_line.product_id.id,
"product_uom": purchase_line.product_uom.id,
"product_uom_qty": purchase_line.product_qty,
"auto_purchase_line_id": purchase_line.id,
"display_type": purchase_line.display_type,
}
)
for onchange_method in new_line._onchange_methods["product_id"]:
onchange_method(new_line)
new_line.update({"product_uom": purchase_line.product_uom.id})
if new_line.display_type in ["line_section", "line_note"]:
new_line.update({"name": purchase_line.name})
return new_line._convert_to_write(new_line._cache)
def button_cancel(self):
sale_orders = (
self.env["sale.order"]
.sudo()
.search([("auto_purchase_order_id", "in", self.ids)])
)
for so in sale_orders:
if so.state not in ["draft", "sent", "cancel"]:
raise UserError(_("You can't cancel an order that is %s") % so.state)
sale_orders.action_cancel()
self.write({"partner_ref": False})
return super().button_cancel()
| 42.157303 | 7,504 |
950 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResCompany(models.Model):
_inherit = "res.company"
so_from_po = fields.Boolean(
string="Create Sale Orders when buying to this company",
help="Generate a Sale Order when a Purchase Order with this company "
"as supplier is created.\n The intercompany user must at least be "
"Sale User.",
)
sale_auto_validation = fields.Boolean(
string="Sale Orders Auto Validation",
default=True,
help="When a Sale Order is created by a multi company rule for "
"this company, it will automatically validate it.",
)
intercompany_sale_user_id = fields.Many2one(
comodel_name="res.users",
string="Intercompany Sale User",
)
| 33.928571 | 950 |
1,291 |
py
|
PYTHON
|
15.0
|
# Copyright 2013-Today Odoo SA
# Copyright 2016-2019 Chafique DELLI @ Akretion
# Copyright 2018-2019 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class InterCompanyRulesConfig(models.TransientModel):
_inherit = "res.config.settings"
so_from_po = fields.Boolean(
related="company_id.so_from_po",
string="Create Sale Orders when buying to this company",
help="Generate a Sale Order when a Purchase Order with this company "
"as supplier is created.\n The intercompany user must at least be "
"Sale User.",
readonly=False,
)
sale_auto_validation = fields.Boolean(
related="company_id.sale_auto_validation",
string="Sale Orders Auto Validation",
help="When a Sale Order is created by a multi company rule for "
"this company, it will automatically validate it.",
readonly=False,
)
intercompany_sale_user_id = fields.Many2one(
comodel_name="res.users",
related="company_id.intercompany_sale_user_id",
string="Intercompany Sale User",
help="User used to create the sales order arising from a purchase "
"order in another company.",
readonly=False,
)
| 36.885714 | 1,291 |
527 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Mail Template Multi Company",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/multi-company",
"depends": ["mail"],
"post_init_hook": "post_init_hook",
"data": ["security/mail_template.xml", "views/mail_template.xml"],
"development_status": "Beta",
"maintainers": ["Olivier-LAURENT"],
}
| 35.133333 | 527 |
335 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class MailTemplate(models.Model):
_inherit = "mail.template"
company_id = fields.Many2one(
"res.company",
default=lambda self: self.env.company,
ondelete="set null",
)
| 22.333333 | 335 |
525 |
py
|
PYTHON
|
15.0
|
# Copyright 2017-2019 Tecnativa - Carlos Dauden
# Copyright 2018 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product Tax Multi Company Default",
"version": "15.0.1.0.1",
"category": "Account",
"website": "https://github.com/OCA/multi-company",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["account", "product"],
"data": ["views/product_template_view.xml"],
"maintainers": ["Shide"],
}
| 35 | 525 |
12,269 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 Carlos Dauden - Tecnativa <[email protected]>
# Copyright 2018 Vicent Cubells - Tecnativa <[email protected]>
# Copyright 2023 Eduardo de Miguel - Moduon Team <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import Form
from odoo.tests.common import TransactionCase
class TestsProductTaxMulticompany(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestsProductTaxMulticompany, cls).setUpClass()
default_country = cls.env.ref("base.cl")
cls.company_1 = cls.env["res.company"].create(
{"name": "Test company 1", "country_id": default_country.id}
)
cls.company_2 = cls.env["res.company"].create(
{"name": "Test company 2", "country_id": default_country.id}
)
cls.alien_companies = cls.env["res.company"].search(
[("id", "not in", (cls.company_1 | cls.company_2).ids)]
)
group_account_manager = cls.env.ref("account.group_account_manager")
group_account_user = cls.env.ref("account.group_account_user")
group_multi_company = cls.env.ref("base.group_multi_company")
ResUsers = cls.env["res.users"]
cls.user_1 = ResUsers.create(
{
"name": "User not admin 1",
"login": "user_1",
"email": "[email protected]",
"groups_id": [(6, 0, group_account_manager.ids)],
"company_id": cls.company_1.id,
"company_ids": [(6, 0, cls.company_1.ids)],
}
)
cls.user_2 = ResUsers.create(
{
"name": "User not admin 2",
"login": "user_2",
"email": "[email protected]",
"groups_id": [(6, 0, group_account_manager.ids)],
"company_id": cls.company_2.id,
"company_ids": [(6, 0, cls.company_2.ids)],
}
)
cls.user_3 = ResUsers.create(
{
"name": "User not admin 3",
"login": "user_3",
"email": "[email protected]",
"groups_id": [
(
6,
0,
(
group_account_manager
| group_account_user
| group_multi_company
).ids,
)
],
"company_id": cls.company_1.id,
"company_ids": [(6, 0, (cls.company_1 | cls.company_2).ids)],
}
)
AccountTax = cls.env["account.tax"]
tax_vals = {
"name": "Test Customer Tax 10%",
"amount": 10.0,
"amount_type": "percent",
"type_tax_use": "sale",
}
cls.tax_10_cc1 = AccountTax.with_user(cls.user_1.id).create(tax_vals)
cls.tax_10_cc2 = AccountTax.with_user(cls.user_2.id).create(tax_vals)
tax_vals.update({"name": "Test Customer Tax 20%", "amount": 20.0})
cls.tax_20_cc1 = AccountTax.with_user(cls.user_1.id).create(tax_vals)
cls.tax_20_cc2 = AccountTax.with_user(cls.user_2.id).create(tax_vals)
tax_vals.update({"name": "Test Customer Tax 30%", "amount": 30.0})
cls.tax_30_cc1 = AccountTax.with_user(cls.user_1.id).create(tax_vals)
cls.tax_30_cc2 = AccountTax.with_user(cls.user_2.id).create(tax_vals)
tax_vals.update({"name": "Test Customer Tax 40%", "amount": 40.0})
cls.tax_40_cc1 = AccountTax.with_user(cls.user_1.id).create(tax_vals)
cls.tax_40_cc2 = AccountTax.with_user(cls.user_2.id).create(tax_vals)
tax_vals.update(
{
"name": "Test Supplier Tax 10%",
"amount": 10.0,
"type_tax_use": "purchase",
}
)
cls.tax_10_sc1 = AccountTax.with_user(cls.user_1.id).create(tax_vals)
cls.tax_10_sc2 = AccountTax.with_user(cls.user_2.id).create(tax_vals)
tax_vals.update({"name": "Test Supplier Tax 20%", "amount": 20.0})
cls.tax_20_sc1 = AccountTax.with_user(cls.user_1.id).create(tax_vals)
cls.tax_20_sc2 = AccountTax.with_user(cls.user_2.id).create(tax_vals)
tax_vals.update({"name": "Test Supplier Tax 30%", "amount": 30.0})
cls.tax_30_sc1 = AccountTax.with_user(cls.user_1.id).create(tax_vals)
cls.tax_30_sc2 = AccountTax.with_user(cls.user_2.id).create(tax_vals)
tax_vals.update({"name": "Test Supplier Tax 40%", "amount": 40.0})
cls.tax_40_sc1 = AccountTax.with_user(cls.user_1.id).create(tax_vals)
cls.tax_40_sc2 = AccountTax.with_user(cls.user_2.id).create(tax_vals)
cls.company_1.account_sale_tax_id = cls.tax_10_cc1.id
cls.company_1.account_purchase_tax_id = cls.tax_10_sc1.id
cls.company_2.account_sale_tax_id = cls.tax_20_cc2.id
cls.company_2.account_purchase_tax_id = cls.tax_20_sc2.id
def test_multicompany_default_tax(self):
product = (
self.env["product.product"]
.with_user(self.user_1.id)
.create({"name": "Test Product", "company_id": False})
)
product = product.sudo()
self.assertIn(self.tax_10_cc1, product.taxes_id)
self.assertIn(self.tax_20_cc2, product.taxes_id)
self.assertIn(self.tax_10_sc1, product.supplier_taxes_id)
self.assertIn(self.tax_20_sc2, product.supplier_taxes_id)
def test_not_default_tax_if_set(self):
product = (
self.env["product.product"]
.with_user(self.user_1.id)
.create(
{
"name": "Test Product",
"taxes_id": [(6, 0, self.tax_20_cc1.ids)],
"supplier_taxes_id": [(6, 0, self.tax_20_sc1.ids)],
"company_id": False,
}
)
)
product = product.sudo()
self.assertNotIn(self.tax_10_cc1, product.taxes_id)
self.assertNotIn(self.tax_10_sc1, product.supplier_taxes_id)
def test_default_tax_if_set_match(self):
product = (
self.env["product.product"]
.with_user(self.user_2.id)
.create(
{
"name": "Test Product",
"taxes_id": [(6, 0, self.tax_20_cc2.ids)],
"supplier_taxes_id": [(6, 0, self.tax_20_sc2.ids)],
"company_id": False,
}
)
)
product = product.sudo()
self.assertIn(self.tax_10_cc1, product.taxes_id)
self.assertIn(self.tax_10_sc1, product.supplier_taxes_id)
def test_tax_not_default_set_match(self):
self.company_1.account_sale_tax_id = self.tax_20_cc1.id
self.company_1.account_purchase_tax_id = self.tax_20_sc1.id
product = (
self.env["product.product"]
.with_user(self.user_1.id)
.create(
{
"name": "Test Product",
"taxes_id": [(6, 0, self.tax_10_cc1.ids)],
"supplier_taxes_id": [(6, 0, self.tax_10_sc1.ids)],
"company_id": False,
}
)
)
product = product.sudo()
self.assertIn(self.tax_10_cc2, product.taxes_id)
self.assertIn(self.tax_10_sc2, product.supplier_taxes_id)
def test_set_multicompany_taxes(self):
# Create product with empty taxes
pf_u3_c1 = Form(
self.env["product.product"]
.with_user(self.user_3.id)
.with_company(self.company_1)
)
pf_u3_c1.name = "Testing Empty Taxes"
pf_u3_c1.taxes_id.clear()
pf_u3_c1.supplier_taxes_id.clear()
product = pf_u3_c1.save()
self.assertFalse(
product.sudo().taxes_id,
"Taxes not empty when initializing product",
)
pf_u3_c1 = Form(product.with_user(self.user_3.id).with_company(self.company_1))
# Fill taxes
pf_u3_c1.name = "Testing Filling Taxes"
pf_u3_c1.taxes_id.add(self.tax_30_cc1)
pf_u3_c1.supplier_taxes_id.add(self.tax_30_sc1)
product = pf_u3_c1.save()
self.assertEqual(
product.sudo().taxes_id,
self.tax_30_cc1,
"Taxes has been propagated before calling set_multicompany_taxes",
)
product.with_user(self.user_3.id).with_company(
self.company_1
).set_multicompany_taxes()
company_1_taxes_fill = product.sudo().taxes_id.filtered(
lambda t: t.company_id == self.company_1
)
company_2_taxes_fill = product.sudo().taxes_id.filtered(
lambda t: t.company_id == self.company_2
)
self.assertEqual(
company_1_taxes_fill,
self.tax_30_cc1,
"Incorrect taxes when setting it for the first time in Company 1",
)
self.assertEqual(
company_2_taxes_fill,
self.tax_30_cc2,
"Incorrect taxes when setting it for the first time in Company 2",
)
# Change taxes
pf_u3_c1.name = "Testing Change Taxes"
pf_u3_c1.taxes_id.clear()
pf_u3_c1.taxes_id.add(self.tax_40_cc1)
pf_u3_c1.supplier_taxes_id.clear()
pf_u3_c1.supplier_taxes_id.add(self.tax_40_sc1)
product = pf_u3_c1.save()
product.with_user(self.user_3.id).with_company(
self.company_1
).set_multicompany_taxes()
company_1_taxes_change = product.sudo().taxes_id.filtered(
lambda t: t.company_id == self.company_1
)
company_2_taxes_change = product.sudo().taxes_id.filtered(
lambda t: t.company_id == self.company_2
)
self.assertEqual(
company_1_taxes_change,
self.tax_40_cc1,
"Incorrect taxes when changing it in Company 1",
)
self.assertEqual(
company_2_taxes_change,
self.tax_40_cc2,
"Incorrect taxes when changing it in Company 2",
)
def test_divergent_taxes_detection_single_company_product(self):
"""Divergency detection is skipped in single-company products."""
product = (
self.env["product.template"]
.with_user(self.user_1)
.with_context(ignored_company_ids=self.alien_companies.ids)
.create(
{
"name": "test product",
"supplier_taxes_id": [(6, 0, self.tax_20_sc1.ids)],
"taxes_id": [(6, 0, self.tax_20_cc1.ids)],
}
)
).sudo()
self.assertTrue(product.taxes_id)
self.assertTrue(product.supplier_taxes_id)
self.assertFalse(product.divergent_company_taxes)
def test_divergent_taxes_detection_multi_company_product(self):
"""Divergency detection works as expected in multi-company products."""
product = (
self.env["product.template"]
.with_user(self.user_1)
.with_context(ignored_company_ids=self.alien_companies.ids)
.create(
{
"company_id": False,
"name": "test product",
"supplier_taxes_id": [(6, 0, self.tax_20_sc1.ids)],
"taxes_id": [(6, 0, self.tax_20_cc1.ids)],
}
)
).sudo()
# By default, taxes are propagated
self.assertTrue(product.taxes_id)
self.assertTrue(product.supplier_taxes_id)
self.assertFalse(product.divergent_company_taxes)
# Somebody changes taxes in other company
product.taxes_id -= self.tax_20_cc2
self.assertTrue(product.divergent_company_taxes)
# Somebody fixes that again
product.set_multicompany_taxes()
self.assertFalse(product.divergent_company_taxes)
# Same flow with supplier taxes
product.supplier_taxes_id -= self.tax_20_sc2
self.assertTrue(product.divergent_company_taxes)
product.set_multicompany_taxes()
self.assertFalse(product.divergent_company_taxes)
| 41.87372 | 12,269 |
6,210 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 Carlos Dauden - Tecnativa <[email protected]>
# Copyright 2018 Vicent Cubells - Tecnativa <[email protected]>
# Copyright 2023 Eduardo de Miguel - Moduon <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from typing import List
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
divergent_company_taxes = fields.Boolean(
string="Has divergent cross-company taxes",
compute="_compute_divergent_company_taxes",
compute_sudo=True,
store=True,
help=(
"Does this product have divergent cross-company taxes? "
"(Only for multi-company products)"
),
)
@api.depends("company_id", "taxes_id", "supplier_taxes_id")
def _compute_divergent_company_taxes(self):
"""Know if this product has divergent taxes across companies."""
all_companies = self.env["res.company"].search(
[
# Useful for tests, to avoid pollution
("id", "not in", self.env.context.get("ignored_company_ids", []))
]
)
for one in self:
one.divergent_company_taxes = False
# Skip single-company products
if one.company_id:
continue
# A unique constraint in account.tax makes it impossible to have
# duplicated tax names by company
customer_taxes = {
frozenset(tax.name for tax in one.taxes_id if tax.company_id == company)
for company in all_companies
}
if len(customer_taxes) > 1:
one.divergent_company_taxes = True
continue
supplier_taxes = {
frozenset(
tax.name
for tax in one.supplier_taxes_id
if tax.company_id == company
)
for company in all_companies
}
if len(supplier_taxes) > 1:
one.divergent_company_taxes = True
continue
def taxes_by_company(self, field, company, match_tax_ids=None):
taxes_ids = []
if match_tax_ids is None:
taxes_ids = company[field].ids
# If None: return default taxes
if not match_tax_ids:
return taxes_ids
AccountTax = self.env["account.tax"]
for tax in AccountTax.browse(match_tax_ids):
taxes_ids.extend(
AccountTax.search(
[("name", "=", tax.name), ("company_id", "=", company.id)]
).ids
)
return taxes_ids
def _delete_product_taxes(
self,
excl_customer_tax_ids: List[int] = None,
excl_supplier_tax_ids: List[int] = None,
):
"""Delete taxes from product excluding chosen taxes
:param excl_customer_tax_ids: Excluded customer tax ids
:param excl_supplier_tax_ids: Excluded supplier tax ids
"""
tax_where = " AND tax_id NOT IN %s"
# Delete customer taxes
customer_sql = "DELETE FROM product_taxes_rel WHERE prod_id IN %s"
customer_sql_params = [tuple(self.ids)]
if excl_customer_tax_ids:
customer_sql += tax_where
customer_sql_params.append(tuple(excl_customer_tax_ids))
self.env.cr.execute(customer_sql + ";", customer_sql_params)
# Delete supplier taxes
supplier_sql = "DELETE FROM product_supplier_taxes_rel WHERE prod_id IN %s"
supplier_sql_params = [tuple(self.ids)]
if excl_supplier_tax_ids:
supplier_sql += tax_where
supplier_sql_params.append(tuple(excl_supplier_tax_ids))
self.env.cr.execute(supplier_sql + ";", supplier_sql_params)
def set_multicompany_taxes(self):
self.ensure_one()
user_company = self.env.company
customer_tax = self.taxes_id
customer_tax_ids = customer_tax.ids
if not customer_tax.filtered(lambda r: r.company_id == user_company):
customer_tax_ids = []
supplier_tax = self.supplier_taxes_id
supplier_tax_ids = supplier_tax.ids
if not supplier_tax.filtered(lambda r: r.company_id == user_company):
supplier_tax_ids = []
obj = self.sudo()
default_customer_tax_ids = obj.taxes_by_company(
"account_sale_tax_id", user_company
)
default_supplier_tax_ids = obj.taxes_by_company(
"account_purchase_tax_id", user_company
)
# Clean taxes from other companies (cannot replace it with sudo)
self._delete_product_taxes(
excl_customer_tax_ids=customer_tax_ids,
excl_supplier_tax_ids=supplier_tax_ids,
)
# Use list() to copy list
match_customer_tax_ids = (
list(customer_tax_ids)
if default_customer_tax_ids != customer_tax_ids
else None
)
match_suplier_tax_ids = (
list(supplier_tax_ids)
if default_supplier_tax_ids != supplier_tax_ids
else None
)
for company in obj.env["res.company"].search([("id", "!=", user_company.id)]):
customer_tax_ids.extend(
obj.taxes_by_company(
"account_sale_tax_id", company, match_customer_tax_ids
)
)
supplier_tax_ids.extend(
obj.taxes_by_company(
"account_purchase_tax_id", company, match_suplier_tax_ids
)
)
self.write(
{
"taxes_id": [(6, 0, customer_tax_ids)],
"supplier_taxes_id": [(6, 0, supplier_tax_ids)],
}
)
@api.model_create_multi
def create(self, vals_list):
new_products = super().create(vals_list)
for product in new_products:
product.set_multicompany_taxes()
return new_products
class ProductProduct(models.Model):
_inherit = "product.product"
def set_multicompany_taxes(self):
self.product_tmpl_id.set_multicompany_taxes()
| 37.409639 | 6,210 |
706 |
py
|
PYTHON
|
15.0
|
# Copyright 2022 Le Filament
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Account move update analytic",
"version": "15.0.1.1.0",
"category": "Accounting & Finance",
"summary": "This module allows the user to update analytic on posted moves",
"author": "Le Filament, Moduon, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"license": "AGPL-3",
"depends": ["account"],
"data": [
"security/ir.model.access.csv",
"wizards/account_move_update_analytic_view.xml",
"views/account_move_view.xml",
"views/account_move_line_view.xml",
],
"installable": True,
}
| 35.3 | 706 |
363 |
py
|
PYTHON
|
15.0
|
# Copyright 2022 Moduon - Eduardo de Miguel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
analytic_account_id = fields.Many2one(
tracking=True,
)
analytic_tag_ids = fields.Many2many(
tracking=True,
)
| 25.928571 | 363 |
2,381 |
py
|
PYTHON
|
15.0
|
# Copyright 2022 Le Filament
# Copyright 2022 Moduon - Eduardo de Miguel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class AccountMoveUpdateAnalytic(models.TransientModel):
_name = "account.move.update.analytic.wizard"
_description = "Account Move Update Analytic Account Wizard"
line_id = fields.Many2one("account.move.line", string="Invoice line")
current_analytic_account_id = fields.Many2one(
related="line_id.analytic_account_id", string="Current Analytic Account"
)
current_analytic_tag_ids = fields.Many2many(
related="line_id.analytic_tag_ids", string="Current Analytic Tags"
)
company_id = fields.Many2one(related="line_id.company_id")
new_analytic_account_id = fields.Many2one(
"account.analytic.account", string="New Analytic Account", check_company=True
)
new_analytic_tag_ids = fields.Many2many(
"account.analytic.tag", string="New Analytic Tags", check_company=True
)
@api.model
def default_get(self, fields):
rec = super().default_get(fields)
active_id = self.env.context.get("active_id", False)
aml = self.env["account.move.line"].browse(active_id)
rec.update(
{
"line_id": active_id,
"current_analytic_account_id": aml.analytic_account_id.id,
"new_analytic_account_id": aml.analytic_account_id.id,
"current_analytic_tag_ids": [(6, 0, aml.analytic_tag_ids.ids or [])],
"new_analytic_tag_ids": [(6, 0, aml.analytic_tag_ids.ids or [])],
"company_id": aml.company_id.id,
}
)
return rec
def update_analytic_lines(self):
self.ensure_one()
self.line_id.analytic_line_ids.unlink()
if self.user_has_groups("analytic.group_analytic_accounting"):
self.line_id.analytic_account_id = self.new_analytic_account_id.id
if self.user_has_groups("analytic.group_analytic_tags"):
self.line_id.write(
{"analytic_tag_ids": [(6, 0, self.new_analytic_tag_ids.ids)]}
)
if self.line_id.parent_state == "posted" and (
self.new_analytic_account_id or self.new_analytic_tag_ids
):
self.line_id.create_analytic_lines()
return False
| 41.051724 | 2,381 |
709 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Akretion (http://www.akretion.com/) - Alexis de Lattre
# Copyright 2016 Antiun Ingeniería S.L. - Javier Iniesta
# Copyright 2017 Tecnativa - Luis Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Product Analytic",
"version": "15.0.1.0.0",
"category": "Accounting & Finance",
"license": "AGPL-3",
"summary": "Add analytic account on products and product categories",
"author": "Akretion, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["account"],
"data": ["views/product_view.xml"],
"demo": ["demo/product_demo.xml"],
"installable": True,
}
| 39.277778 | 707 |
3,732 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Antiun Ingenieria - Javier Iniesta
# Copyright 2017 Tecnativa - Luis Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
class TestAccountInvoiceLine(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.analytic_account1 = cls.env["account.analytic.account"].create(
{"name": "test analytic_account1"}
)
cls.analytic_account2 = cls.env["account.analytic.account"].create(
{"name": "test analytic_account2"}
)
cls.product = cls.env["product.product"].create(
{
"name": "test product",
"lst_price": 50,
"standard_price": 50,
"income_analytic_account_id": cls.analytic_account1.id,
"expense_analytic_account_id": cls.analytic_account2.id,
}
)
cls.partner = cls.env["res.partner"].create({"name": "Test partner"})
cls.journal_sale = cls.env["account.journal"].create(
{"name": "Test journal sale", "code": "SALE0", "type": "sale"}
)
cls.journal_purchase = cls.env["account.journal"].create(
{"name": "Test journal purchase", "code": "PURCHASE0", "type": "purchase"}
)
cls.account_type = cls.env["account.account.type"].create(
{"name": "Test account type", "type": "other", "internal_group": "equity"}
)
cls.account = cls.env["account.account"].create(
{
"name": "Test account",
"code": "TEST",
"user_type_id": cls.account_type.id,
}
)
def test_create_in(self):
invoice = self.env["account.move"].create(
{
"partner_id": self.partner.id,
"journal_id": self.journal_purchase.id,
"move_type": "in_invoice",
"invoice_line_ids": [
(
0,
0,
{
"name": "Test line",
"quantity": 1,
"price_unit": 50,
"account_id": self.account.id,
"product_id": self.product.id,
},
)
],
}
)
invoice_line = invoice.invoice_line_ids[0]
invoice_line._onchange_product_id()
self.assertEqual(
invoice_line.analytic_account_id.id,
self.product.expense_analytic_account_id.id,
)
def test_create_out(self):
invoice = self.env["account.move"].create(
{
"partner_id": self.partner.id,
"journal_id": self.journal_sale.id,
"move_type": "out_invoice",
"invoice_line_ids": [
(
0,
0,
{
"name": "Test line",
"quantity": 1,
"price_unit": 50,
"account_id": self.account.id,
"product_id": self.product.id,
},
)
],
}
)
invoice_line = invoice.invoice_line_ids[0]
invoice_line._onchange_product_id()
self.assertEqual(
invoice_line.analytic_account_id.id,
self.product.income_analytic_account_id.id,
)
| 37.31 | 3,731 |
1,682 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Akretion (http://www.akretion.com/) - Alexis de Lattre
# Copyright 2016 Antiun Ingeniería S.L. - Javier Iniesta
# Copyright 2017 Tecnativa - Luis Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models
INV_TYPE_MAP = {
"out_invoice": "income",
"out_refund": "income",
"in_invoice": "expense",
"in_refund": "expense",
}
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
@api.onchange("product_id")
def _onchange_product_id(self):
res = super()._onchange_product_id()
for line in self:
inv_type = line.move_id.move_type
if line.product_id and inv_type:
ana_accounts = (
line.product_id.product_tmpl_id._get_product_analytic_accounts()
)
ana_account = ana_accounts[INV_TYPE_MAP[inv_type]]
line.analytic_account_id = ana_account.id
return res
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
inv_type = self.env["account.move"].browse([vals.get("move_id")]).move_type
if (
vals.get("product_id")
and inv_type != "entry"
and not vals.get("analytic_account_id")
):
product = self.env["product.product"].browse(vals.get("product_id"))
ana_accounts = product.product_tmpl_id._get_product_analytic_accounts()
ana_account = ana_accounts[INV_TYPE_MAP[inv_type]]
vals["analytic_account_id"] = ana_account.id
return super().create(vals_list)
| 37.333333 | 1,680 |
683 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Akretion (http://www.akretion.com/) - Alexis de Lattre
# Copyright 2016 Antiun Ingeniería S.L. - Javier Iniesta
# Copyright 2017 Tecnativa - Luis Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ProductCategory(models.Model):
_inherit = "product.category"
income_analytic_account_id = fields.Many2one(
"account.analytic.account",
string="Income Analytic Account",
company_dependent=True,
)
expense_analytic_account_id = fields.Many2one(
"account.analytic.account",
string="Expense Analytic Account",
company_dependent=True,
)
| 34.05 | 681 |
1,009 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Akretion (http://www.akretion.com/) - Alexis de Lattre
# Copyright 2016 Antiun Ingeniería S.L. - Javier Iniesta
# Copyright 2017 Tecnativa - Luis Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
income_analytic_account_id = fields.Many2one(
"account.analytic.account",
string="Income Analytic Account",
company_dependent=True,
)
expense_analytic_account_id = fields.Many2one(
"account.analytic.account",
string="Expense Analytic Account",
company_dependent=True,
)
def _get_product_analytic_accounts(self):
self.ensure_one()
return {
"income": self.income_analytic_account_id
or self.categ_id.income_analytic_account_id,
"expense": self.expense_analytic_account_id
or self.categ_id.expense_analytic_account_id,
}
| 33.566667 | 1,007 |
844 |
py
|
PYTHON
|
15.0
|
# Copyright 2013 Julius Network Solutions
# Copyright 2015 Clear Corp
# Copyright 2016 OpenSynergy Indonesia
# Copyright 2017 ForgeFlow S.L.
# Copyright 2018 Hibou Corp.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Stock Analytic",
"summary": "Adds an analytic account and analytic tags in stock move",
"version": "15.0.1.0.0",
"author": "Julius Network Solutions, "
"ClearCorp, OpenSynergy Indonesia, "
"Hibou Corp., "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"category": "Warehouse Management",
"license": "AGPL-3",
"depends": ["stock_account", "analytic"],
"data": [
"views/stock_move_views.xml",
"views/stock_scrap.xml",
"views/stock_move_line.xml",
],
"installable": True,
}
| 33.76 | 844 |
2,923 |
py
|
PYTHON
|
15.0
|
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
class TestStockScrap(TransactionCase):
def setUp(self):
super(TestStockScrap, self).setUp()
self.product = self.env.ref("product.product_product_4")
self.warehouse = self.env.ref("stock.warehouse0")
self.location = self.warehouse.lot_stock_id
self.analytic_account = self.env.ref("analytic.analytic_agrolait")
self.analytic_tag_1 = self.env["account.analytic.tag"].create(
{"name": "analytic tag test 1"}
)
self.analytic_tag_2 = self.env["account.analytic.tag"].create(
{"name": "analytic tag test 2"}
)
def __update_qty_on_hand_product(self, product, new_qty):
qty_wizard = self.env["stock.change.product.qty"].create(
{
"product_id": product.id,
"product_tmpl_id": product.product_tmpl_id.id,
"new_quantity": new_qty,
}
)
qty_wizard.change_product_qty()
def _create_scrap(self, analytic_account_id=False, analytic_tag_ids=False):
scrap_data = {
"product_id": self.product.id,
"scrap_qty": 1.00,
"product_uom_id": self.product.uom_id.id,
"location_id": self.location.id,
"analytic_account_id": analytic_account_id
and analytic_account_id.id
or False,
"analytic_tag_ids": [(6, 0, analytic_tag_ids if analytic_tag_ids else [])],
}
return self.env["stock.scrap"].create(scrap_data)
def _validate_scrap_no_error(self, scrap):
scrap.action_validate()
self.assertEqual(scrap.state, "done")
def _check_analytic_account_no_error(self, scrap):
domain = [("name", "=", scrap.name)]
acc_lines = self.env["account.move.line"].search(domain)
for acc_line in acc_lines:
if (
acc_line.account_id
!= scrap.product_id.categ_id.property_stock_valuation_account_id
):
self.assertEqual(
acc_line.analytic_account_id.id, scrap.analytic_account_id.id
)
self.assertEqual(
acc_line.analytic_tag_ids.ids, scrap.analytic_tag_ids.ids
)
def test_scrap_without_analytic(self):
self.__update_qty_on_hand_product(self.product, 1)
scrap = self._create_scrap()
self._validate_scrap_no_error(scrap)
def test_scrap_with_analytic(self):
self.__update_qty_on_hand_product(self.product, 1)
scrap = self._create_scrap(
self.analytic_account, [self.analytic_tag_1.id | self.analytic_tag_2.id]
)
self._validate_scrap_no_error(scrap)
self._check_analytic_account_no_error(scrap)
| 39.5 | 2,923 |
9,874 |
py
|
PYTHON
|
15.0
|
# Copyright 2013 Julius Network Solutions
# Copyright 2015 Clear Corp
# Copyright 2016 OpenSynergy Indonesia
# Copyright 2017 ForgeFlow S.L.
# Copyright 2018 Hibou Corp.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import datetime
from odoo.tests.common import TransactionCase
class TestStockPicking(TransactionCase):
def setUp(self):
super(TestStockPicking, self).setUp()
self.product = self.env["product.product"].create(
{
"name": "Test Product",
"type": "product",
"standard_price": 1.0,
}
)
self.product_2 = self.env.ref("product.product_product_5")
self.product_categ = self.env.ref("product.product_category_5")
self.valuation_account = self.env["account.account"].create(
{
"name": "Test stock valuation",
"code": "tv",
"user_type_id": self.env["account.account.type"].search([], limit=1).id,
"reconcile": True,
"company_id": self.env.ref("base.main_company").id,
}
)
self.stock_input_account = self.env["account.account"].create(
{
"name": "Test stock input",
"code": "tsti",
"user_type_id": self.env["account.account.type"].search([], limit=1).id,
"reconcile": True,
"company_id": self.env.ref("base.main_company").id,
}
)
self.stock_output_account = self.env["account.account"].create(
{
"name": "Test stock output",
"code": "tout",
"user_type_id": self.env["account.account.type"].search([], limit=1).id,
"reconcile": True,
"company_id": self.env.ref("base.main_company").id,
}
)
self.stock_journal = self.env["account.journal"].create(
{"name": "Stock Journal", "code": "STJTEST", "type": "general"}
)
self.analytic_tag_1 = self.env["account.analytic.tag"].create(
{"name": "analytic tag test 1"}
)
self.analytic_tag_2 = self.env["account.analytic.tag"].create(
{"name": "analytic tag test 2"}
)
self.analytic_account = self.env.ref("analytic.analytic_agrolait")
self.warehouse = self.env.ref("stock.warehouse0")
self.location = self.warehouse.lot_stock_id
self.dest_location = self.env.ref("stock.stock_location_customers")
self.outgoing_picking_type = self.env.ref("stock.picking_type_out")
self.incoming_picking_type = self.env.ref("stock.picking_type_in")
self.product_categ.update(
{
"property_valuation": "real_time",
"property_stock_valuation_account_id": self.valuation_account.id,
"property_stock_account_input_categ_id": self.stock_input_account.id,
"property_stock_account_output_categ_id": self.stock_output_account.id,
"property_stock_journal": self.stock_journal.id,
}
)
self.product.update({"categ_id": self.product_categ.id})
def _create_picking(
self,
location_id,
location_dest_id,
picking_type_id,
analytic_account_id=False,
analytic_tag_ids=False,
):
picking_data = {
"picking_type_id": picking_type_id.id,
"move_type": "direct",
"location_id": location_id.id,
"location_dest_id": location_dest_id.id,
}
picking = self.env["stock.picking"].create(picking_data)
move_data = {
"picking_id": picking.id,
"product_id": self.product.id,
"location_id": location_id.id,
"location_dest_id": location_dest_id.id,
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"date_deadline": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"name": self.product.name,
"procure_method": "make_to_stock",
"product_uom": self.product.uom_id.id,
"product_uom_qty": 1.0,
"analytic_account_id": (
analytic_account_id.id if analytic_account_id else False
),
"analytic_tag_ids": [(6, 0, analytic_tag_ids if analytic_tag_ids else [])],
}
self.env["stock.move"].create(move_data)
return picking
def __update_qty_on_hand_product(self, product, new_qty):
self.env["stock.quant"]._update_available_quantity(
product, self.location, new_qty
)
def _confirm_picking_no_error(self, picking):
picking.action_confirm()
self.assertEqual(picking.state, "assigned")
def _picking_done_no_error(self, picking):
picking.move_lines.quantity_done = 1.0
picking.button_validate()
self.assertEqual(picking.state, "done")
def _check_account_move_no_error(self, picking):
criteria1 = [
["ref", "=", "{} - {}".format(picking.name, picking.product_id.name)]
]
acc_moves = self.env["account.move"].search(criteria1)
self.assertTrue(len(acc_moves) > 0)
def _check_analytic_account_no_error(self, picking):
move = picking.move_lines[0]
criteria2 = [["move_id.ref", "=", picking.name]]
acc_lines = self.env["account.move.line"].search(criteria2)
for acc_line in acc_lines:
if (
acc_line.account_id
!= move.product_id.categ_id.property_stock_valuation_account_id
):
self.assertEqual(
acc_line.analytic_account_id.id, move.analytic_account_id.id
)
self.assertEqual(
acc_line.analytic_tag_ids.ids, move.analytic_tag_ids.ids
)
def _check_no_analytic_account(self, picking):
criteria2 = [
("move_id.ref", "=", picking.name),
("analytic_account_id", "!=", False),
]
criteria3 = [
("move_id.ref", "=", picking.name),
("analytic_tag_ids", "not in", []),
]
line_count = self.env["account.move.line"].search_count(criteria2)
self.assertEqual(line_count, 0)
line_count = self.env["account.move.line"].search_count(criteria3)
self.assertEqual(line_count, 0)
def test_outgoing_picking_with_analytic(self):
picking = self._create_picking(
self.location,
self.dest_location,
self.outgoing_picking_type,
self.analytic_account,
[self.analytic_tag_1.id | self.analytic_tag_2.id],
)
self.__update_qty_on_hand_product(self.product, 1)
self._confirm_picking_no_error(picking)
self._picking_done_no_error(picking)
self._check_account_move_no_error(picking)
self._check_analytic_account_no_error(picking)
def test_outgoing_picking_without_analytic(self):
picking = self._create_picking(
self.location,
self.dest_location,
self.outgoing_picking_type,
)
self.__update_qty_on_hand_product(self.product, 1)
self._confirm_picking_no_error(picking)
self._picking_done_no_error(picking)
self._check_account_move_no_error(picking)
self._check_no_analytic_account(picking)
def test_incoming_picking_with_analytic(self):
picking = self._create_picking(
self.location,
self.dest_location,
self.incoming_picking_type,
self.analytic_account,
[self.analytic_tag_1.id | self.analytic_tag_2.id],
)
self.__update_qty_on_hand_product(self.product, 1)
self._confirm_picking_no_error(picking)
self._picking_done_no_error(picking)
self._check_account_move_no_error(picking)
self._check_analytic_account_no_error(picking)
def test_picking_add_extra_move_line(self):
picking = self._create_picking(
self.location,
self.dest_location,
self.outgoing_picking_type,
self.analytic_account,
[self.analytic_tag_1.id | self.analytic_tag_2.id],
)
move_before = picking.move_lines
self.env["stock.move.line"].create(
{
"product_id": self.product_2.id,
"location_id": self.location.id,
"location_dest_id": self.dest_location.id,
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"product_uom_id": self.product_2.uom_id.id,
"product_uom_qty": 1.0,
"analytic_account_id": self.analytic_account.id,
"company_id": self.env.company.id,
"picking_id": picking.id,
}
)
move_after = picking.move_lines - move_before
self.assertEqual(self.analytic_account, move_after.analytic_account_id)
def test__prepare_procurement_values(self):
picking = self._create_picking(
self.location,
self.dest_location,
self.outgoing_picking_type,
self.analytic_account,
[self.analytic_tag_1.id | self.analytic_tag_2.id],
)
values = picking.move_lines._prepare_procurement_values()
self.assertEqual(self.analytic_account.id, values["analytic_account_id"])
picking = self._create_picking(
self.location,
self.dest_location,
self.outgoing_picking_type,
)
values = picking.move_lines._prepare_procurement_values()
self.assertEqual(
values.get("analytic_account_id"), self.env["account.analytic.account"]
)
| 38.874016 | 9,874 |
722 |
py
|
PYTHON
|
15.0
|
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class StockScrap(models.Model):
_inherit = "stock.scrap"
analytic_account_id = fields.Many2one(
string="Analytic Account", comodel_name="account.analytic.account"
)
analytic_tag_ids = fields.Many2many("account.analytic.tag", string="Analytic Tags")
def _prepare_move_values(self):
res = super()._prepare_move_values()
res.update(
{
"analytic_account_id": self.analytic_account_id.id,
"analytic_tag_ids": [(6, 0, self.analytic_tag_ids.ids)],
}
)
return res
| 32.818182 | 722 |
3,087 |
py
|
PYTHON
|
15.0
|
# Copyright 2013 Julius Network Solutions
# Copyright 2015 Clear Corp
# Copyright 2016 OpenSynergy Indonesia
# Copyright 2017 ForgeFlow S.L.
# Copyright 2018 Hibou Corp.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class StockMove(models.Model):
_inherit = "stock.move"
analytic_account_id = fields.Many2one(
string="Analytic Account",
comodel_name="account.analytic.account",
)
analytic_tag_ids = fields.Many2many("account.analytic.tag", string="Analytic Tags")
def _prepare_account_move_line(
self, qty, cost, credit_account_id, debit_account_id, description
):
self.ensure_one()
res = super(StockMove, self)._prepare_account_move_line(
qty, cost, credit_account_id, debit_account_id, description
)
for line in res:
if (
line[2]["account_id"]
!= self.product_id.categ_id.property_stock_valuation_account_id.id
):
# Add analytic account in debit line
if self.analytic_account_id:
line[2].update({"analytic_account_id": self.analytic_account_id.id})
# Add analytic tags in debit line
if self.analytic_tag_ids:
line[2].update(
{"analytic_tag_ids": [(6, 0, self.analytic_tag_ids.ids)]}
)
return res
def _prepare_procurement_values(self):
"""
Allows to transmit analytic account from moves to new
moves through procurement.
"""
res = super()._prepare_procurement_values()
if self.analytic_account_id:
res.update(
{
"analytic_account_id": self.analytic_account_id.id,
}
)
return res
@api.model
def _prepare_merge_moves_distinct_fields(self):
fields = super()._prepare_merge_moves_distinct_fields()
fields.append("analytic_account_id")
return fields
def _prepare_move_line_vals(self, quantity=None, reserved_quant=None):
"""
We fill in the analytic account when creating the move line from
the move
"""
res = super()._prepare_move_line_vals(
quantity=quantity, reserved_quant=reserved_quant
)
if self.analytic_account_id:
res.update({"analytic_account_id": self.analytic_account_id.id})
return res
class StockMoveLine(models.Model):
_inherit = "stock.move.line"
analytic_account_id = fields.Many2one(comodel_name="account.analytic.account")
@api.model
def _prepare_stock_move_vals(self):
"""
In the case move lines are created manually, we should fill in the
new move created here with the analytic account if filled in.
"""
res = super()._prepare_stock_move_vals()
if self.analytic_account_id:
res.update({"analytic_account_id": self.analytic_account_id.id})
return res
| 34.685393 | 3,087 |
310 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import SUPERUSER_ID, api
def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env["account.analytic.account"]._assign_default_codes()
| 34.444444 | 310 |
578 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 ACSONE SA/NV
# Copyright 2020 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Analytic Sequence",
"summary": """
Restore the analytic account sequence""",
"version": "15.0.1.0.1",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": [
"analytic",
],
"data": [
"data/sequence.xml",
],
"post_init_hook": "post_init_hook",
}
| 28.9 | 578 |
656 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 ACSONE SA/NV
# Copyright 2020 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestAccountAnalyticSequence(TransactionCase):
def setUp(self):
super().setUp()
self.analytic_account_obj = self.env["account.analytic.account"]
self.partner1 = self.env.ref("base.res_partner_1")
self.analytic = self.analytic_account_obj.create(
{"name": "aa", "partner_id": self.partner1.id}
)
def test_onchange(self):
self.assertTrue(self.analytic.code, "Sequence not added")
| 34.526316 | 656 |
1,027 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 ACSONE SA/NV
# Copyright 2020 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class AccountAnalyticAccount(models.Model):
_inherit = "account.analytic.account"
code = fields.Char(
default=lambda self: self._default_code(),
copy=False,
)
_sql_constraints = [
(
"code_uniq",
"UNIQUE(code, company_id)",
"Reference must be unique per Company!",
),
]
@api.model
def create(self, vals):
if "code" not in vals:
vals["code"] = self._default_code()
return super().create(vals)
@api.model
def _default_code(self):
return self.env["ir.sequence"].next_by_code("account.analytic.account.code")
@api.model
def _assign_default_codes(self):
for aaa in self.with_context(active_test=False).search([("code", "=", False)]):
aaa.code = self._default_code()
| 27.756757 | 1,027 |
1,281 |
py
|
PYTHON
|
15.0
|
import setuptools
with open('VERSION.txt', 'r') as f:
version = f.read().strip()
setuptools.setup(
name="odoo-addons-oca-account-analytic",
description="Meta package for oca-account-analytic Odoo addons",
version=version,
install_requires=[
'odoo-addon-account_analytic_parent>=15.0dev,<15.1dev',
'odoo-addon-account_analytic_required>=15.0dev,<15.1dev',
'odoo-addon-account_analytic_sequence>=15.0dev,<15.1dev',
'odoo-addon-account_analytic_tag_default>=15.0dev,<15.1dev',
'odoo-addon-account_move_update_analytic>=15.0dev,<15.1dev',
'odoo-addon-analytic_base_department>=15.0dev,<15.1dev',
'odoo-addon-analytic_tag_dimension>=15.0dev,<15.1dev',
'odoo-addon-mrp_analytic>=15.0dev,<15.1dev',
'odoo-addon-pos_analytic_by_config>=15.0dev,<15.1dev',
'odoo-addon-procurement_mto_analytic>=15.0dev,<15.1dev',
'odoo-addon-product_analytic>=15.0dev,<15.1dev',
'odoo-addon-purchase_analytic>=15.0dev,<15.1dev',
'odoo-addon-purchase_stock_analytic>=15.0dev,<15.1dev',
'odoo-addon-stock_analytic>=15.0dev,<15.1dev',
],
classifiers=[
'Programming Language :: Python',
'Framework :: Odoo',
'Framework :: Odoo :: 15.0',
]
)
| 41.322581 | 1,281 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
106 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
106 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
100 |
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667 | 100 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.