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
|
---|---|---|---|---|---|---|
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 |
470 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Purchase Stock Analytic",
"summary": """
Copies the analytic account of the purchase order item to the stock move""",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["purchase_stock", "stock_analytic"],
}
| 36.153846 | 470 |
2,206 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo.tests.common import TransactionCase
class TestPurchaseStockAnalytic(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.purchase_order_model = cls.env["purchase.order"]
cls.purchase_order_line_model = cls.env["purchase.order.line"]
cls.analytic_tag_model = cls.env["account.analytic.tag"]
cls.product_model = cls.env["product.product"]
cls.res_partner_model = cls.env["res.partner"]
cls.analytic_tag_1 = cls.analytic_tag_model.create({"name": "Tag test 1"})
cls.analytic_tag_2 = cls.analytic_tag_model.create({"name": "Tag test 2"})
cls.partner = cls.res_partner_model.create({"name": "Partner test"})
cls.product = cls.product_model.create({"name": "Product test"})
cls.analytic_account = cls.env.ref("analytic.analytic_agrolait")
cls.purchase_order = cls.purchase_order_model.create(
{"partner_id": cls.partner.id}
)
cls.purchase_order_line = cls.purchase_order_line_model.create(
{
"name": "purchase order line test",
"product_qty": 3,
"order_id": cls.purchase_order.id,
"price_unit": 20,
"product_id": cls.product.id,
"account_analytic_id": cls.analytic_account.id,
"analytic_tag_ids": [
(6, 0, [cls.analytic_tag_1.id, cls.analytic_tag_2.id])
],
"date_planned": fields.Datetime.today(),
"product_uom": cls.product.uom_po_id.id,
}
)
def test_purchase_stock_analytic(self):
self.purchase_order.button_confirm()
self.move = self.purchase_order.picking_ids.move_ids_without_package
self.assertEqual(self.move.analytic_account_id, self.analytic_account)
self.assertEqual(
self.move.analytic_tag_ids.ids,
[self.analytic_tag_1.id, self.analytic_tag_2.id],
)
| 43.254902 | 2,206 |
685 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
def _prepare_stock_moves(self, picking):
res = super(PurchaseOrderLine, self)._prepare_stock_moves(picking)
for line in res:
account_analytic = self.account_analytic_id
analytic_tags = self.analytic_tag_ids
if account_analytic:
line.update({"analytic_account_id": account_analytic.id})
if analytic_tags:
line.update({"analytic_tag_ids": [(6, 0, analytic_tags.ids)]})
return res
| 34.25 | 685 |
625 |
py
|
PYTHON
|
15.0
|
# Copyright 2011-2018 Camptocamp SA
# Copyright 2013 Daniel Reis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Base Analytic Department Categorization",
"summary": "Add relationship between Analytic and Department",
"version": "15.0.1.0.0",
"author": "Camptocamp, Daniel Reis, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Generic Modules/Projects & Services",
"website": "https://github.com/OCA/account-analytic",
"depends": ["account", "hr"],
"data": ["views/analytic.xml", "views/hr_department_views.xml"],
"installable": True,
}
| 41.666667 | 625 |
1,141 |
py
|
PYTHON
|
15.0
|
# Copyright 2016 Yannick Vaucher (Camptocamp)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class LineDepartmentCase(TransactionCase):
@classmethod
def setUpClass(cls):
"""Assign user and department."""
super(LineDepartmentCase, cls).setUpClass()
# base.user_demo --> hr.employee_qdp --> hr.dep_rd
cls.user = cls.env.ref("base.user_demo")
cls.dep = cls.env.ref("hr.dep_rd")
def test_default_department(self):
"""In a new users form, a user set only the firstname."""
aal = self.env["account.analytic.line"].with_user(self.user).new()
department_id = aal.default_get(["department_id"]).get("department_id")
self.assertEqual(department_id, self.dep.id)
def test_no_employees(self):
"""Tesing lines created by users w/out employee records."""
self.user.employee_ids = [(5, 0)]
aal = self.env["account.analytic.line"].with_user(self.user).new()
department_id = aal.default_get(["department_id"]).get("department_id")
self.assertFalse(department_id)
| 43.884615 | 1,141 |
399 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 Ecosoft Co., Ltd (http://ecosoft.co.th/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from odoo import fields, models
class Department(models.Model):
_inherit = "hr.department"
analytic_account_ids = fields.One2many(
string="Analytic Accounts",
comodel_name="account.analytic.account",
inverse_name="department_id",
)
| 28.5 | 399 |
1,256 |
py
|
PYTHON
|
15.0
|
# Copyright 2011-2016 Camptocamp SA
# Copyright 2013 Daniel Reis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class AnalyticAccount(models.Model):
"""Add Department in analytic account."""
_inherit = "account.analytic.account"
department_id = fields.Many2one(string="Department", comodel_name="hr.department")
class AnalyticLine(models.Model):
"""Add Department and Account Department in analytic line."""
_inherit = "account.analytic.line"
@api.model
def _default_department(self):
department_id = False
employee = self.env.user.employee_ids
if employee and employee[0].department_id:
department_id = employee[0].department_id.id
return department_id
department_id = fields.Many2one(
string="Department",
comodel_name="hr.department",
default=lambda self: self._default_department(),
help="User's related department",
)
account_department_id = fields.Many2one(
comodel_name="hr.department",
related="account_id.department_id",
string="Account Department",
store=True,
readonly=True,
help="Account's related department",
)
| 30.634146 | 1,256 |
283 |
py
|
PYTHON
|
15.0
|
# Copyright 2018 Brainbean Apps
# 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"]._parent_store_compute()
| 28.3 | 283 |
1,008 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 ForgeFlow S.L.
# Copyright 2017 Luxim d.o.o.
# Copyright 2017 Matmoz d.o.o.
# Copyright 2017 Deneroteam.
# Copyright 2017 Serpent Consulting Services Pvt. Ltd.
# Copyright 2017 Tecnativa
# Copyright 2018 Brainbean Apps
# Copyright 2020 CorporateHub (https://corporatehub.eu)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Account Analytic Parent",
"summary": """
This module reintroduces the hierarchy to the analytic accounts.""",
"version": "15.0.1.0.0",
"category": "Accounting & Finance",
"license": "AGPL-3",
"author": "Matmoz d.o.o., "
"Luxim d.o.o., "
"Deneroteam, "
"ForgeFlow, "
"Tecnativa, "
"CorporateHub, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["account", "analytic"],
"data": ["views/account_analytic_account_view.xml"],
"demo": ["demo/analytic_account_demo.xml"],
"post_init_hook": "post_init_hook",
}
| 33.6 | 1,008 |
4,554 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 ForgeFlow S.L.
# Copyright 2017 Luxim d.o.o.
# Copyright 2017 Matmoz d.o.o.
# Copyright 2017 Deneroteam.
# Copyright 2017 Serpent Consulting Services Pvt. Ltd.
# Copyright 2017 Tecnativa
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase
class TestAccountAnalyticRecursion(TransactionCase):
def setUp(self):
super(TestAccountAnalyticRecursion, self).setUp()
self.analytic_account_obj = self.env["account.analytic.account"]
self.analytic_line_obj = self.env["account.analytic.line"]
self.partner1 = self.env.ref("base.res_partner_1")
self.partner2 = self.env.ref("base.res_partner_2")
self.analytic_parent1 = self.create_analytic_account(
{"name": "parent aa", "code": "01", "partner_id": self.partner1.id}
)
self.analytic_son = self.create_analytic_account(
{"name": "son aa", "code": "02", "parent_id": self.analytic_parent1.id}
)
self.analytic_parent2 = self.create_analytic_account(
{"name": "parent2 aa", "code": "01", "partner_id": self.partner2.id}
)
self.analytic_parent3 = self.create_analytic_account(
{"name": "parent3 aa", "code": "01", "partner_id": self.partner2.id}
)
self.analytic_son2 = self.create_analytic_account(
{"name": "son aa", "code": "02", "parent_id": self.analytic_parent3.id}
)
self.create_analytic_line("Analytic line son", self.analytic_son, 50)
self.create_analytic_line("Analytic line parent1", self.analytic_parent1, 100)
self.create_analytic_line("Analytic line parent2", self.analytic_parent2, 50)
self.create_analytic_line("Analytic line son2", self.analytic_son2, -50)
self.assertEqual(
self.analytic_parent1.debit, 0, "Analytic account in the debit side"
)
self.assertEqual(self.analytic_parent3.debit, 50)
def create_analytic_account(self, values):
if hasattr(self.analytic_account_obj, "_default_code"):
values.pop("code")
return self.analytic_account_obj.create(values)
def create_analytic_line(self, name, analytic, amount):
return self.analytic_line_obj.create(
{"name": name, "amount": amount, "account_id": analytic.id}
)
def test_recursion(self):
with self.assertRaises(UserError):
self.analytic_parent1.write({"parent_id": self.analytic_son.id})
def test_onchange(self):
self.analytic_son._onchange_parent_id()
self.assertEqual(
self.analytic_son.partner_id.id,
self.partner1.id,
"Partner should not change",
)
self.analytic_son.write({"parent_id": self.analytic_parent2.id})
self.analytic_son._onchange_parent_id()
self.assertEqual(
self.analytic_son.partner_id.id, self.partner2.id, "Partner should change"
)
def test_debit_credit_balance(self):
self.assertEqual(self.analytic_parent1.credit, 150, "Wrong amount")
self.assertEqual(self.analytic_parent1.balance, 150, "Wrong amount")
self.assertEqual(
self.analytic_son.debit, 0, "Analytic account in the debit side"
)
self.assertEqual(self.analytic_son.credit, 50, "Wrong amount")
self.assertEqual(self.analytic_son.balance, 50, "Wrong amount")
self.assertEqual(
self.analytic_parent2.debit, 0, "Analytic account in the debit side"
)
self.assertEqual(self.analytic_parent2.credit, 50, "Wrong amount")
self.assertEqual(self.analytic_parent2.balance, 50, "Wrong amount")
self.assertEqual(self.analytic_parent3.debit, 50)
self.assertEqual(self.analytic_parent3.credit, 0)
self.assertEqual(self.analytic_parent3.balance, -50)
def test_archive(self):
self.analytic_parent1.toggle_active()
self.assertEqual(self.analytic_son.active, False)
self.analytic_parent1.toggle_active()
self.assertEqual(self.analytic_son.active, False)
self.analytic_parent1.toggle_active()
with self.assertRaises(UserError):
self.analytic_son.toggle_active()
def test_name(self):
display_name = "[%s] parent aa / son aa" % self.analytic_son.code
self.assertEqual(self.analytic_son.complete_name, "parent aa / son aa")
self.assertEqual(self.analytic_son.display_name, display_name)
| 45.089109 | 4,554 |
5,243 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 ForgeFlow S.L.
# Copyright 2017 Luxim d.o.o.
# Copyright 2017 Matmoz d.o.o.
# Copyright 2017 Deneroteam.
# Copyright 2017 Serpent Consulting Services Pvt. Ltd.
# Copyright 2018 Brainbean Apps
# Copyright 2019 Pesol
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class AccountAnalyticAccount(models.Model):
_inherit = "account.analytic.account"
_parent_name = "parent_id"
_parent_store = True
_order = "complete_name"
parent_path = fields.Char(index=True)
parent_id = fields.Many2one(
string="Parent Analytic Account",
comodel_name="account.analytic.account",
index=True,
ondelete="cascade",
)
child_ids = fields.One2many(
string="Child Accounts",
comodel_name="account.analytic.account",
inverse_name="parent_id",
copy=True,
)
complete_name = fields.Char(
compute="_compute_complete_name", recursive=True, store=True
)
@api.depends("child_ids.line_ids.amount")
def _compute_debit_credit_balance(self):
"""
Warning, this method overwrites the standard because the hierarchy
of analytic account changes
"""
res = super()._compute_debit_credit_balance()
ResCurrency = self.env["res.currency"]
AccountAnalyticLine = self.env["account.analytic.line"]
user_currency_id = self.env.user.company_id.currency_id
# Re-compute only accounts with children
for account in self.filtered("child_ids"):
domain = [("account_id", "child_of", account.id)]
credit_groups = AccountAnalyticLine.read_group(
domain=domain + [("amount", ">=", 0.0)],
fields=["currency_id", "amount"],
groupby=["currency_id"],
lazy=False,
)
credit = sum(
map(
lambda x: ResCurrency.browse(x["currency_id"][0])._convert(
x["amount"],
user_currency_id,
self.env.user.company_id,
fields.Date.today(),
),
credit_groups,
)
)
debit_groups = AccountAnalyticLine.read_group(
domain=domain + [("amount", "<", 0.0)],
fields=["currency_id", "amount"],
groupby=["currency_id"],
lazy=False,
)
debit = sum(
map(
lambda x: ResCurrency.browse(x["currency_id"][0])._convert(
x["amount"],
user_currency_id,
self.env.user.company_id,
fields.Date.today(),
),
debit_groups,
)
)
account.debit = abs(debit)
account.credit = credit
account.balance = account.credit - account.debit
return res
@api.constrains("parent_id")
def check_recursion(self):
for account in self:
if not super(AccountAnalyticAccount, account)._check_recursion():
raise UserError(_("You can not create recursive analytic accounts."))
return True
@api.onchange("parent_id")
def _onchange_parent_id(self):
for account in self:
account.partner_id = account.parent_id.partner_id
@api.depends("name", "parent_id.complete_name")
def _compute_complete_name(self):
for account in self:
if account.parent_id:
account.complete_name = _("%(parent)s / %(own)s") % {
"parent": account.parent_id.complete_name,
"own": account.name,
}
else:
account.complete_name = account.name
@api.constrains("active")
def check_parent_active(self):
for account in self.filtered(
lambda a: a.active
and a.parent_id
and a.parent_id not in self
and not a.parent_id.active
):
raise UserError(
_("Please activate first parent account %s")
% account.parent_id.complete_name
)
@api.depends("complete_name", "code", "partner_id.commercial_partner_id.name")
def _compute_display_name(self):
return super()._compute_display_name()
def name_get(self):
res = []
for analytic in self:
name = analytic.complete_name
if analytic.code:
name = ("[%(code)s] %(name)s") % {"code": analytic.code, "name": name}
if analytic.partner_id:
name = _("%(name)s - %(partner)s") % {
"name": name,
"partner": analytic.partner_id.commercial_partner_id.name,
}
res.append((analytic.id, name))
return res
def write(self, vals):
if self and "active" in vals and not vals["active"]:
self.mapped("child_ids").write({"active": False})
return super().write(vals)
| 34.721854 | 5,243 |
339 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api
def uninstall_hook(cr, registry):
"""Cleanup all dimensions before uninstalling."""
env = api.Environment(cr, SUPERUSER_ID, {})
env["account.analytic.dimension"].search([]).unlink()
| 37.666667 | 339 |
739 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 PESOL (http://pesol.es) - Angel Moya ([email protected])
# Copyright 2020 Tecnativa - Carlos Dauden
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Analytic Accounts Dimensions",
"summary": "Group Analytic Entries by Dimensions",
"version": "15.0.1.0.0",
"development_status": "Mature",
"license": "AGPL-3",
"author": "PESOL, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["account", "analytic"],
"data": ["security/ir.model.access.csv", "views/analytic_view.xml"],
"demo": ["demo/analytic_demo.xml"],
"uninstall_hook": "uninstall_hook",
}
| 43.470588 | 739 |
8,298 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 PESOL (http://pesol.es) - Angel Moya ([email protected])
# Copyright 2020 Tecnativa - Carlos Dauden
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
from odoo.tests.common import SavepointCase
from ..hooks import uninstall_hook
class TestAnalyticDimensionBase(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.dimension_obj = cls.env["account.analytic.dimension"]
cls.tag_obj = cls.env["account.analytic.tag"]
cls.analytic_line_obj = cls.env["account.analytic.line"]
cls.dimension_1 = cls.dimension_obj.create(
{"name": "Test dimension 1", "code": "test_dim_1"}
)
cls.dimension_2 = cls.dimension_obj.create(
{"name": "Test dimension 2", "code": "test_dim_2"}
)
cls.analytic_tag_1a = cls.tag_obj.create(
{"name": "Test tag 1A", "analytic_dimension_id": cls.dimension_1.id}
)
cls.analytic_tag_1b = cls.tag_obj.create(
{"name": "Test tag 1B", "analytic_dimension_id": cls.dimension_1.id}
)
cls.analytic_tag_2a = cls.tag_obj.create(
{"name": "Test tag 2A", "analytic_dimension_id": cls.dimension_2.id}
)
cls.analytic_account = cls.env["account.analytic.account"].create(
{"name": "Test analytic account"}
)
cls.account = cls.env["account.account"].create(
{
"code": "test_dimension_acc_01",
"name": "test dimension account",
"user_type_id": cls.env.ref("account.data_account_type_receivable").id,
"reconcile": True,
}
)
cls.journal = cls.env["account.journal"].create(
{"name": "Test Journal", "code": "TJ", "type": "general"}
)
cls.partner = cls.env["res.partner"].create({"name": "Test_partner"})
class TestAnalyticDimensionCase(TestAnalyticDimensionBase):
def test_analytic_dimension_spaces_error(self):
"""Test dimension creation with spaces in code."""
dimension_error = {
"name": "Test Spaces Error",
"code": "test spaces error",
}
with self.assertRaises(ValidationError):
self.dimension_obj.create(dimension_error)
def test_analytic_entry_dimension(self):
"""Test dimension update on analytic entry creation"""
line = self.analytic_line_obj.create(
{
"account_id": self.analytic_account.id,
"name": "test",
"tag_ids": [
(4, self.analytic_tag_1a.id),
(4, self.analytic_tag_2a.id),
],
}
)
self.assertEqual(line.x_dimension_test_dim_1, self.analytic_tag_1a)
self.assertEqual(line.x_dimension_test_dim_2, self.analytic_tag_2a)
with self.assertRaises(ValidationError):
line.write({"tag_ids": [(4, self.analytic_tag_1b.id)]})
# Not allowed to change dimension of a tag if used
with self.assertRaises(ValidationError):
self.analytic_tag_1a.analytic_dimension_id = self.dimension_2.id
# Empty tags - Using command 5
line.write({"tag_ids": [(5,)]})
self.assertFalse(line.x_dimension_test_dim_1)
self.assertFalse(line.x_dimension_test_dim_2)
# It should be allowed now
self.analytic_tag_1a.analytic_dimension_id = self.dimension_2.id
def test_account_entry_dimension(self):
"""Test dimension update on account move line creation"""
move = self.env["account.move"].create(
{
"name": "/",
"ref": "2011010",
"journal_id": self.journal.id,
"state": "draft",
}
)
line = self.env["account.move.line"].create(
{
"name": "test",
"account_id": self.account.id,
"move_id": move.id,
"analytic_account_id": self.analytic_account.id,
"analytic_tag_ids": [
(4, self.analytic_tag_1a.id),
(4, self.analytic_tag_2a.id),
],
}
)
self.assertEqual(line.x_dimension_test_dim_1, self.analytic_tag_1a)
self.assertEqual(line.x_dimension_test_dim_2, self.analytic_tag_2a)
with self.assertRaises(ValidationError):
line.write({"analytic_tag_ids": [(4, self.analytic_tag_1b.id)]})
# Not allowed to change dimension of a tag if used
with self.assertRaises(ValidationError):
self.analytic_tag_1a.analytic_dimension_id = self.dimension_2.id
# Empty tags - Using command 6
line.write({"analytic_tag_ids": [(6, 0, [])]})
self.assertFalse(line.x_dimension_test_dim_1)
self.assertFalse(line.x_dimension_test_dim_2)
# It should be allowed now
self.analytic_tag_1a.analytic_dimension_id = self.dimension_2.id
def test_invoice_line_dimension(self):
"""Test dimension creation on account invoice line creation."""
invoice = self.env["account.move"].create(
{"journal_id": self.journal.id, "partner_id": self.partner.id}
)
line = self.env["account.move.line"].create(
{
"name": "test",
"price_unit": 1,
"account_id": self.account.id,
"move_id": invoice.id,
"analytic_account_id": self.analytic_account.id,
"analytic_tag_ids": [
(4, self.analytic_tag_1a.id),
(4, self.analytic_tag_2a.id),
],
}
)
self.assertEqual(line.x_dimension_test_dim_1, self.analytic_tag_1a)
self.assertEqual(line.x_dimension_test_dim_2, self.analytic_tag_2a)
with self.assertRaises(ValidationError):
line.write({"analytic_tag_ids": [(4, self.analytic_tag_1b.id)]})
# Not allowed to change dimension of a tag if used
with self.assertRaises(ValidationError):
self.analytic_tag_1a.analytic_dimension_id = self.dimension_2.id
# Empty tags - Using commands 3 and 2
line.write({"analytic_tag_ids": [(3, self.analytic_tag_1a.id)]})
self.assertFalse(line.x_dimension_test_dim_1)
line.write({"analytic_tag_ids": [(2, self.analytic_tag_2a.id)]})
self.assertFalse(line.x_dimension_test_dim_2)
# It should be allowed now
self.analytic_tag_1a.analytic_dimension_id = self.dimension_2.id
# Try command 0 for tags
line.write(
{
"analytic_tag_ids": [
(
0,
0,
{
"name": "Test tag 2B",
"analytic_dimension_id": self.dimension_2.id,
},
)
]
}
)
self.assertTrue(line.x_dimension_test_dim_2)
# Try command 1 for tags
line.write(
{
"analytic_tag_ids": [
(
1,
line.analytic_tag_ids[0].id,
{"analytic_dimension_id": self.dimension_1.id},
)
]
}
)
self.assertTrue(line.x_dimension_test_dim_1)
self.assertFalse(line.x_dimension_test_dim_2)
def test_remove_dimension(self):
self.dimension_1.unlink()
self.assertNotIn("x_dimension_test_dim_1", self.analytic_line_obj._fields)
uninstall_hook(self.env.cr, False)
self.assertNotIn("x_dimension_test_dim_2", self.analytic_line_obj._fields)
def test_zz_dimension_rename(self):
# It should executed the last one for avoiding side effects
# as not everything is undone in this renaming
self.dimension_1.write({"code": "test_renamed"})
self.assertIn("x_dimension_test_renamed", self.analytic_line_obj._fields)
self.assertIn("x_dimension_test_renamed", self.env["account.move.line"]._fields)
| 42.121827 | 8,298 |
3,971 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 PESOL (http://pesol.es) - Angel Moya ([email protected])
# Copyright 2020 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from psycopg2 import sql
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class AccountAnalyticDimension(models.Model):
_name = "account.analytic.dimension"
_description = "Account Analytic Dimension"
name = fields.Char(required=True)
code = fields.Char(required=True)
analytic_tag_ids = fields.One2many(
comodel_name="account.analytic.tag",
inverse_name="analytic_dimension_id",
string="Analytic Tags",
)
@api.constrains("code")
def _check_code(self):
for dimension in self:
if " " in dimension.code:
raise ValidationError(_("Code can't contain spaces!"))
@api.model
def get_model_names(self):
return [
"account.move.line",
"account.analytic.line",
"account.invoice.report",
]
def get_field_name(self, code=False):
return "x_dimension_{}".format(code or self.code).lower()
def _convert_dict_query(self, field_vals):
val_query = [
"{} = '{}'".format(key, field_val) for key, field_val in field_vals.items()
]
vals = ", ".join(val_query)
return vals
def _update_invoice_report(self, field_to_update, value):
self._cr.execute(
sql.SQL(
""" UPDATE {} SET {} WHERE id={} """.format(
field_to_update._table, value, field_to_update.id
)
)
)
field_to_update.invalidate_cache()
@api.model
def create(self, values):
res = super().create(values)
_models = self.env["ir.model"].search(
[("model", "in", self.get_model_names())], order="id"
)
_models.write(
{
"field_id": [
(
0,
0,
{
"name": self.get_field_name(values["code"]),
"field_description": values.get("name"),
"ttype": "many2one",
"relation": "account.analytic.tag",
},
)
],
}
)
return res
def write(self, vals):
field_vals = {}
if "name" in vals or "code" in vals:
if "name" in vals:
field_vals["field_description"] = vals["name"]
if "code" in vals:
field_vals["name"] = self.get_field_name(vals["code"])
for dimension in self:
fields_to_update = self.env["ir.model.fields"].search(
[
("model", "in", self.get_model_names()),
("name", "=", dimension.get_field_name()),
],
order="id",
)
# To avoid 'Can only rename one field at a time!'
for field_to_update in fields_to_update:
if field_to_update.model == "account.invoice.report":
value = self._convert_dict_query(field_vals)
self._update_invoice_report(field_to_update, value)
else:
field_to_update.write(field_vals)
return super().write(vals)
def unlink(self):
"""Clean created fields before unlinking."""
models = self.env["ir.model"].search([("model", "in", self.get_model_names())])
for record in self:
field_name = self.get_field_name(record.code)
self.env["ir.model.fields"].search(
[("model_id", "in", models.ids), ("name", "=", field_name)]
).unlink()
return super().unlink()
| 35.141593 | 3,971 |
393 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 PESOL (http://pesol.es) - Angel Moya ([email protected])
# Copyright 2020 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class AccountMoveLine(models.Model):
_name = "account.move.line"
_inherit = ["analytic.dimension.line", "account.move.line"]
_analytic_tag_field_name = "analytic_tag_ids"
| 35.727273 | 393 |
907 |
py
|
PYTHON
|
15.0
|
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class AccountInvoiceReport(models.Model):
_inherit = "account.invoice.report"
def _get_dimension_fields(self):
if self.env.context.get("update_custom_fields"):
return [] # Avoid to report these columns when not yet created
return [x for x in self.fields_get().keys() if x.startswith("x_dimension_")]
def _select(self):
res = super()._select()
add_fields = self._get_dimension_fields()
add_fields = [", line.{0} as {0}".format(x) for x in add_fields]
return res + "".join(add_fields)
def _sub_select(self):
res = super()._sub_select()
add_fields = self._get_dimension_fields()
add_fields = [", ail.{0} as {0}".format(x) for x in add_fields]
return res + "".join(add_fields)
| 36.28 | 907 |
2,793 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 PESOL (http://pesol.es) - Angel Moya ([email protected])
# Copyright 2020 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
class AnalyticDimensionLine(models.AbstractModel):
_name = "analytic.dimension.line"
_description = "Analytic Dimension Line"
_analytic_tag_field_name = "analytic_tag_ids"
def _handle_analytic_dimension(self, vals):
Tag = self.env["account.analytic.tag"]
field = self._analytic_tag_field_name
tags = self[field]
vals = vals.copy()
prev_dim_vals = tags.get_dimension_values()
if vals.get(field):
new_commands = []
for command in vals.get(field):
if command[0] == 0:
tag = Tag.create(command[2])
tags += tag
new_commands.append((4, tag.id))
elif command[0] == 1:
tag = Tag.browse(command[1])
tag.write(command[2])
tags |= tag
new_commands.append((4, tag.id))
else:
new_commands.append(command)
if command[0] == 2:
tags -= Tag.browse(command[1])
elif command[0] == 3:
tags -= Tag.browse(command[1])
elif command[0] == 4:
tags += Tag.browse(command[1])
elif command[0] == 5:
tags = Tag
elif command[0] == 6:
tags = Tag.browse(command[2])
vals[field] = new_commands
else:
tags = Tag
tags._check_analytic_dimension()
current_dim_vals = tags.get_dimension_values()
# Add explicit False assignation to removed tags
for key in prev_dim_vals:
if key not in current_dim_vals:
current_dim_vals[key] = False
vals.update(current_dim_vals)
return vals
@api.model_create_multi
def create(self, vals_list):
"""Inject values for dimension fields."""
new_vals_list = []
for vals in vals_list:
if self._analytic_tag_field_name in vals:
vals = self._handle_analytic_dimension(vals)
new_vals_list.append(vals)
return super().create(new_vals_list)
def write(self, vals):
"""Inject values for dimension fields."""
if self._analytic_tag_field_name in vals:
for record in self:
vals = record._handle_analytic_dimension(vals)
super(AnalyticDimensionLine, record).write(vals)
return True
return super().write(vals)
| 38.791667 | 2,793 |
2,968 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 PESOL (http://pesol.es) - Angel Moya ([email protected])
# Copyright 2020 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, fields, models
from odoo.exceptions import ValidationError
class AccountAnalyticTag(models.Model):
_inherit = "account.analytic.tag"
analytic_dimension_id = fields.Many2one(
comodel_name="account.analytic.dimension", string="Dimension"
)
def get_dimension_values(self):
values = {}
for tag in self.filtered("analytic_dimension_id"):
values.update({tag.analytic_dimension_id.get_field_name(): tag.id})
return values
def _check_analytic_dimension(self):
tags_with_dimension = self.filtered("analytic_dimension_id")
dimensions = tags_with_dimension.mapped("analytic_dimension_id")
if len(tags_with_dimension) != len(dimensions):
raise ValidationError(_("You can not set two tags from same dimension."))
def write(self, vals):
if "analytic_dimension_id" in vals:
Dimension = self.env["account.analytic.dimension"]
_models = [self.env[m] for m in Dimension.get_model_names()]
for tag in self.filtered("analytic_dimension_id"):
old_field = tag.analytic_dimension_id.get_field_name()
new_field = Dimension.browse(
vals["analytic_dimension_id"]
).get_field_name()
if old_field == new_field: # pragma: no cover
continue
# Filter to avoid update report models
for model in filter(lambda m: m._auto, _models):
records_to_update = model.search(
[(old_field, "=", tag.id)], order="id"
)
if not records_to_update:
continue
same_dimension_tags = records_to_update.with_context(
prefetch_fields=False
).mapped(new_field)
if same_dimension_tags:
raise ValidationError(
_(
"You can not set two tags from same dimension.\n"
" Records %(records_to_update)s in the model "
"%(description)s have %(display_name)s"
)
% {
"records_to_update": records_to_update.ids,
"description": model._description,
"display_name": same_dimension_tags.mapped(
"display_name"
),
}
)
records_to_update.write({old_field: False, new_field: tag.id})
return super().write(vals)
| 45.661538 | 2,968 |
396 |
py
|
PYTHON
|
15.0
|
# Copyright 2017 PESOL (http://pesol.es) - Angel Moya ([email protected])
# Copyright 2020 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class AccountAnalyticLine(models.Model):
_name = "account.analytic.line"
_inherit = ["analytic.dimension.line", "account.analytic.line"]
_analytic_tag_field_name = "tag_ids"
| 36 | 396 |
510 |
py
|
PYTHON
|
15.0
|
# © 2016 Laetitia Gangloff, Acsone SA/NV (http://www.acsone.eu)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Purchase Analytic",
"version": "15.0.2.0.0",
"author": "Acsone SA/NV, Odoo Community Association (OCA)",
"category": "Purchase Management",
"website": "https://github.com/OCA/account-analytic",
"depends": ["purchase"],
"data": ["views/purchase_views.xml"],
"license": "AGPL-3",
"installable": True,
"application": False,
}
| 33.933333 | 509 |
2,762 |
py
|
PYTHON
|
15.0
|
# © 2016 Laetitia Gangloff, Acsone SA/NV (http://www.acsone.eu)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import datetime
from odoo.tests.common import TransactionCase
class TestPurchaseAnalytic(TransactionCase):
def setUp(self):
super().setUp()
self.partner_id = self.env.ref("base.res_partner_12")
self.product_id = self.env.ref("product.product_product_9")
self.uom_id = self.env.ref("uom.product_uom_unit")
self.project = self.env["account.analytic.account"].create(
{"name": "Account Analytic for Tests"}
)
def test_analytic_account(self):
"""Create a purchase order (create)
Set analytic account on purchase
Check analytic account and line is set
"""
po = self.env["purchase.order"].create(
{
"partner_id": self.partner_id.id,
"order_line": [
(
0,
0,
{
"name": self.product_id.name,
"product_id": self.product_id.id,
"product_qty": 1.0,
"product_uom": self.uom_id.id,
"price_unit": 121.0,
"date_planned": datetime.today(),
},
)
],
}
)
po.project_id = self.project.id
po._onchange_project_id()
self.assertEqual(po.project_id.id, self.project.id)
self.assertEqual(po.order_line.account_analytic_id.id, self.project.id)
def test_project_id(self):
"""Create a purchase order (new)
Set analytic account on purchase
Check analytic account and line is set
"""
po = self.env["purchase.order"].new(
{
"partner_id": self.partner_id.id,
"project_id": self.project.id,
"order_line": [
(
0,
0,
{
"name": self.product_id.name,
"product_id": self.product_id.id,
"product_qty": 1.0,
"product_uom": self.uom_id.id,
"price_unit": 121.0,
"date_planned": datetime.today(),
},
)
],
}
)
po._onchange_project_id()
self.assertEqual(po.project_id.id, self.project.id)
self.assertEqual(po.order_line.account_analytic_id.id, self.project.id)
| 36.813333 | 2,761 |
1,700 |
py
|
PYTHON
|
15.0
|
# © 2016 Laetitia Gangloff, Acsone SA/NV (http://www.acsone.eu)
# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class PurchaseOrder(models.Model):
_inherit = "purchase.order"
project_id = fields.Many2one(
compute="_compute_project_id",
inverse="_inverse_project_id",
comodel_name="account.analytic.account",
string="Analytic Account",
readonly=True,
states={"draft": [("readonly", False)]},
store=True,
help="The analytic account related to a purchase order.",
)
@api.depends("order_line.account_analytic_id")
def _compute_project_id(self):
"""If all order line have same analytic account set project_id.
If no lines, respect value given by the user.
"""
for po in self:
if po.order_line:
al = po.order_line[0].account_analytic_id or False
for ol in po.order_line:
if ol.account_analytic_id != al:
al = False
break
po.project_id = al
def _inverse_project_id(self):
"""When set project_id set analytic account on all order lines"""
for po in self:
if po.project_id:
po.order_line.write({"account_analytic_id": po.project_id.id})
@api.onchange("project_id")
def _onchange_project_id(self):
"""When change project_id set analytic account on all order lines"""
if self.project_id:
self.order_line.update({"account_analytic_id": self.project_id.id})
| 36.934783 | 1,699 |
510 |
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Purchase Analytic (MTO)",
"summary": "This module sets analytic account in purchase order line from "
"sale order analytic account",
"version": "15.0.1.0.0",
"category": "Analytic",
"license": "AGPL-3",
"author": "Tecnativa, VentorTech, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["sale_stock", "purchase_stock"],
"installable": True,
}
| 36.428571 | 510 |
3,577 |
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import common
class TestPurchaseProcurementAnalytic(common.TransactionCase):
"""Use case : Prepare some data for current test case"""
@classmethod
def setUpClass(cls):
super(TestPurchaseProcurementAnalytic, cls).setUpClass()
vendor = cls.env["res.partner"].create({"name": "Partner #2"})
supplierinfo = cls.env["product.supplierinfo"].create({"name": vendor.id})
mto = cls.env.ref("stock.route_warehouse0_mto")
mto.write({"active": True})
buy = cls.env.ref("purchase_stock.route_warehouse0_buy")
cls.product = cls.env["product.product"].create(
{
"name": "Product Test",
"seller_ids": [(6, 0, [supplierinfo.id])],
"route_ids": [(6, 0, [buy.id, mto.id])],
}
)
supplierinfo_service = cls.env["product.supplierinfo"].create(
{"name": vendor.id}
)
cls.service_product = cls.env["product.product"].create(
{
"name": "Product Service Test",
"seller_ids": [(6, 0, [supplierinfo_service.id])],
"type": "service",
"service_to_purchase": True,
}
)
cls.partner = cls.env["res.partner"].create({"name": "Partner #1"})
def test_sale_to_procurement(self):
analytic_account = self.env["account.analytic.account"].create(
{"name": "Test Analytic Account"}
)
sale_order = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"analytic_account_id": analytic_account.id,
"order_line": [
(
0,
0,
{
"product_id": self.product.id,
"product_uom_qty": 1,
"price_unit": self.product.list_price,
"name": self.product.name,
},
)
],
"picking_policy": "direct",
}
)
sale_order.with_context(test_enabled=True).action_confirm()
purchase_order = self.env["purchase.order.line"].search(
[("account_analytic_id", "=", analytic_account.id)]
)
self.assertTrue(purchase_order)
def test_sale_service_product(self):
analytic_account = self.env["account.analytic.account"].create(
{"name": "Test Service Analytic Account"}
)
sale_order = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"analytic_account_id": analytic_account.id,
"order_line": [
(
0,
0,
{
"product_id": self.service_product.id,
"product_uom_qty": 1,
"price_unit": self.product.list_price,
"name": self.product.name,
},
)
],
"picking_policy": "direct",
}
)
sale_order.with_context(test_enabled=True).action_confirm()
purchase_order = self.env["purchase.order.line"].search(
[("account_analytic_id", "=", analytic_account.id)]
)
self.assertTrue(purchase_order)
| 37.652632 | 3,577 |
619 |
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
@api.model
def _prepare_purchase_order_line_from_procurement(
self, product_id, product_qty, product_uom, company_id, values, po
):
res = super(
PurchaseOrderLine, self
)._prepare_purchase_order_line_from_procurement(
product_id, product_qty, product_uom, company_id, values, po
)
res["account_analytic_id"] = values.get("account_analytic_id", False)
return res
| 32.578947 | 619 |
699 |
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
def _prepare_procurement_values(self, group_id=False):
res = super()._prepare_procurement_values(group_id)
res.update({"account_analytic_id": self.order_id.analytic_account_id.id})
return res
def _purchase_service_prepare_line_values(self, purchase_order, quantity=False):
res = super()._purchase_service_prepare_line_values(
purchase_order=purchase_order, quantity=quantity
)
res.update({"account_analytic_id": self.order_id.analytic_account_id.id})
return res
| 36.789474 | 699 |
377 |
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class StockMove(models.Model):
_inherit = "stock.move"
def _prepare_procurement_values(self):
res = super()._prepare_procurement_values()
res.update(
{"account_analytic_id": self.group_id.sale_id.analytic_account_id.id}
)
return res
| 26.928571 | 377 |
490 |
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class StockRule(models.Model):
_inherit = "stock.rule"
def _make_po_get_domain(self, company_id, values, partner):
res = super()._make_po_get_domain(company_id, values, partner)
res += (
(
"order_line.account_analytic_id",
"=",
values.get("account_analytic_id", False),
),
)
return res
| 27.222222 | 490 |
465 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Account Analytic Tag Default",
"summary": "Set default tags on analytic accounts.",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["account"],
"data": ["views/account_analytic_account_view.xml"],
}
| 38.75 | 465 |
3,920 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
class TestAccountAnalyticTagDefault(TransactionCase):
def setUp(self):
super().setUp()
self.analytic_account_obj = self.env["account.analytic.account"]
self.tag_obj = self.env["account.analytic.tag"]
self.move_obj = self.env["account.move"]
self.account_obj = self.env["account.account"]
self.company = self.env.ref("base.main_company")
self.partner1 = self.env.ref("base.res_partner_1")
self.journal = self.journal_sale = self.env["account.journal"].create(
{"name": "Test journal sale", "code": "SALE0", "type": "sale"}
)
self.account_sales = self.account_obj.create(
{
"code": "X1020",
"name": "Product Sales - (test)",
"user_type_id": self.env.ref("account.data_account_type_revenue").id,
}
)
self.tag_01 = self.tag_obj.create({"name": "Tag 1"})
self.tag_02 = self.tag_obj.create({"name": "Tag 2"})
self.tag_03 = self.tag_obj.create({"name": "Tag 3"})
self.test_analytic_account = self.analytic_account_obj.create(
{"name": "Finance", "default_analytic_tag_ids": [(6, 0, [self.tag_01.id])]}
)
self.another_analytic_account = self.analytic_account_obj.create(
{"name": "Finance", "default_analytic_tag_ids": [(6, 0, [self.tag_03.id])]}
)
def test_01_create_entry_no_tags(self):
invoice = self.move_obj.with_context(default_move_type="out_invoice").create(
{
"move_type": "out_invoice",
"company_id": self.company.id,
"journal_id": self.journal.id,
"partner_id": self.partner1.id,
"invoice_line_ids": [
(
0,
0,
{
"name": "[FURN_7800] Desk Combination",
"account_id": self.account_sales.id,
"price_unit": 1000.0,
"quantity": 1.0,
"product_id": self.ref("product.product_product_3"),
"analytic_account_id": self.test_analytic_account.id,
},
)
],
}
)
self.assertEqual(invoice.invoice_line_ids.analytic_tag_ids, self.tag_01)
# Change account, tags should change:
invoice.invoice_line_ids.analytic_account_id = self.another_analytic_account
self.assertEqual(invoice.invoice_line_ids.analytic_tag_ids, self.tag_03)
def test_02_create_entry_with_different_tags(self):
invoice = self.move_obj.with_context(default_move_type="out_invoice").create(
{
"move_type": "out_invoice",
"company_id": self.company.id,
"journal_id": self.journal.id,
"partner_id": self.partner1.id,
"invoice_line_ids": [
(
0,
0,
{
"name": "[FURN_7800] Desk Combination",
"account_id": self.account_sales.id,
"price_unit": 1000.0,
"quantity": 1.0,
"product_id": self.ref("product.product_product_3"),
"analytic_account_id": self.test_analytic_account.id,
"analytic_tag_ids": [(6, 0, self.tag_02.ids)],
},
)
],
}
)
self.assertEqual(invoice.invoice_line_ids.analytic_tag_ids, self.tag_02)
| 43.076923 | 3,920 |
1,684 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
# make standard field a stored, computed, editable field.
analytic_tag_ids = fields.Many2many(
compute="_compute_analytic_tag_ids",
store=True,
readonly=False,
)
@api.depends("analytic_account_id")
def _compute_analytic_tag_ids(self):
for rec in self:
if not rec._origin and rec.analytic_tag_ids:
continue
if rec.analytic_account_id.default_analytic_tag_ids:
rec.analytic_tag_ids = rec.analytic_account_id.default_analytic_tag_ids
else:
rec.analytic_tag_ids = False
@api.model_create_multi
def create(self, vals_list):
# This is needed to apply default tags when creating and invoice/entry
# from an action in other model, for instance a SO.
aa_model = self.env["account.analytic.account"]
for vals in vals_list:
if vals.get("analytic_account_id"):
a_acc = aa_model.browse(vals.get("analytic_account_id"))
tags_value = vals.get("analytic_tag_ids")
is_tags_empty = not tags_value or (
isinstance(tags_value, list) and tags_value == [(6, 0, [])]
)
if a_acc.default_analytic_tag_ids and is_tags_empty:
vals["analytic_tag_ids"] = [
(6, 0, a_acc.default_analytic_tag_ids.ids)
]
return super().create(vals_list)
| 38.272727 | 1,684 |
309 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class AccountAnalyticAccount(models.Model):
_inherit = "account.analytic.account"
default_analytic_tag_ids = fields.Many2many(comodel_name="account.analytic.tag")
| 30.9 | 309 |
572 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 ACSONE SA/NV
# Copyright 2020 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "POS Analytic Config",
"summary": "Use analytic account defined on POS configuration for POS orders",
"author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"category": "Point Of Sale, Accounting",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"depends": ["point_of_sale"],
"data": ["views/pos_config_view.xml"],
}
| 40.857143 | 572 |
5,371 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields
from odoo.tests import common
class TestPosAnalyticConfig(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.aml_obj = cls.env["account.move.line"]
cls.pricelist = cls.env["product.pricelist"].create(
{
"name": "Test pricelist",
"item_ids": [
(
0,
0,
{
"applied_on": "3_global",
"compute_price": "formula",
"base": "list_price",
},
)
],
}
)
cls.main_config = cls.env.ref("point_of_sale.pos_config_main")
cls.main_config.write(
{
"available_pricelist_ids": [(6, 0, cls.pricelist.ids)],
"pricelist_id": cls.pricelist.id,
}
)
cls.aa_01 = cls.env["account.analytic.account"].create(
{"name": "Test Analytic Account"}
)
cls.customer_01 = cls.env["res.partner"].create({"name": "Mr. Odoo"})
cls.product_01 = cls.env["product.product"].create({"name": "Test product"})
cls.main_config.account_analytic_id = cls.aa_01
cls.main_config.invoice_journal_id = cls.main_config.journal_id
cls.session_01 = cls.env["pos.session"].create(
{"config_id": cls.main_config.id}
)
cls.session_01.action_pos_session_open()
payment_methods = cls.session_01.payment_method_ids
account_receivable_id = (
cls.env.user.partner_id.property_account_receivable_id.id
)
order_vals = {
"id": "test-id-pos_analytic_by_config",
"data": {
"creation_date": "2021-04-05 12:00:00",
"sequence_number": 1,
"user_id": 1,
"name": "Order test-id-pos_analytic_by_config",
"uid": "test-id-pos_analytic_by_config",
"partner_id": cls.customer_01.id,
"pricelist_id": cls.pricelist.id,
"fiscal_position_id": False,
"pos_session_id": cls.session_01.id,
"lines": [
(
0,
0,
{
"product_id": cls.product_01.id,
"qty": 1,
"price_unit": 10.0,
"price_subtotal": 10,
"price_subtotal_incl": 10,
},
)
],
"amount_total": 10.0,
"amount_tax": 0.0,
"amount_paid": 10.0,
"amount_return": 0.0,
"statement_ids": [
[
0,
0,
{
"journal_id": cls.main_config.journal_id.id,
"amount": 10,
"name": fields.Datetime.now(),
"account_id": account_receivable_id,
"statement_id": cls.session_01.statement_ids[0].id,
"payment_method_id": payment_methods.filtered(
lambda pm: pm.is_cash_count
and not pm.split_transactions
)[0].id,
},
]
],
},
}
order = cls.env["pos.order"].create_from_ui([order_vals])
cls.pos_order = cls.env["pos.order"].browse(order[0]["id"])
cls.income_account = cls.session_01._prepare_line(cls.pos_order.lines)[
"income_account_id"
]
def test_order_simple_receipt(self):
"""Simple tickets are grouped by account in single move lines"""
aml_domain = [
("account_id", "=", self.income_account),
("analytic_account_id", "=", self.aa_01.id),
]
# There aren't lines with the analytic account yet
self.assertFalse(self.aml_obj.search(aml_domain))
self.session_01.total_payments_amount = 0
self.main_config.journal_id.type = "sale"
self.pos_order.action_pos_order_invoice()
self.session_01.action_pos_session_closing_control()
# There they are
self.assertEqual(len(self.aml_obj.search(aml_domain)), 1)
def test_order_invoice(self):
"""Tickets with invoice are posted prior to session reconcilation"""
aml_domain = [
("account_id", "=", self.income_account),
("product_id", "=", self.product_01.id),
("analytic_account_id", "=", self.aa_01.id),
]
self.main_config.journal_id.type = "sale"
lines = self.aml_obj.search(aml_domain)
# There aren't lines with the analytic account yet
self.assertEqual(len(lines.ids), 0)
self.pos_order.action_pos_order_invoice()
lines = self.aml_obj.search(aml_domain)
# There they are
self.assertEqual(len(lines.ids), 1)
| 40.383459 | 5,371 |
770 |
py
|
PYTHON
|
15.0
|
# Copyright 2020 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
@api.onchange("product_id")
def _onchange_product_id(self):
analytic_account_id = self.analytic_account_id
res = super()._onchange_product_id()
if not self.env.context.get("pos_analytic") or not analytic_account_id:
return res
# Odoo triggers an onchange on the product_id when creating an invoice.
# This may cause an incompatibility with product_analytic
if self.analytic_account_id != analytic_account_id:
self.analytic_account_id = analytic_account_id
return res
| 40.526316 | 770 |
1,655 |
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models
class PosSession(models.Model):
_inherit = "pos.session"
def _credit_amounts(
self,
partial_move_line_vals,
amount,
amount_converted,
force_company_currency=False,
):
"""We only want the analyitic account set in the sales items from the account
move. This is called from `_get_sale_vals` but from other credit methods
as well. To ensure that only sales items get the analytic account we flag
the context from the former method with the proper analytic account id.
"""
account_analytic_id = self.env.context.get("account_analytic_id")
if account_analytic_id:
partial_move_line_vals.update({"analytic_account_id": account_analytic_id})
return super()._credit_amounts(
partial_move_line_vals, amount, amount_converted, force_company_currency
)
def _get_sale_vals(self, key, amount, amount_converted):
"""The method that allowed to add the analytic account to the sales items
has been dropped in v13, so we have to add it in the moment the sales
items values are prepared.
"""
account_analytic_id = self.config_id.account_analytic_id
if account_analytic_id:
return super(
PosSession,
self.with_context(account_analytic_id=account_analytic_id.id),
)._get_sale_vals(key, amount, amount_converted)
return super()._get_sale_vals(key, amount, amount_converted)
| 42.435897 | 1,655 |
318 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class PosConfig(models.Model):
_inherit = "pos.config"
account_analytic_id = fields.Many2one(
comodel_name="account.analytic.account", string="Analytic Account"
)
| 28.909091 | 318 |
878 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 ACSONE SA/NV
# Copyright 2020 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models
class PosOrder(models.Model):
_inherit = "pos.order"
def _prepare_invoice_line(self, line):
"""The method that allowed to add the analytic account to the invoice lines
has been dropped in v13. Fortunately we can add it easily with this
prepare method.
"""
res = super()._prepare_invoice_line(line)
analytic_account = line.order_id.session_id.config_id.account_analytic_id
if analytic_account:
res.update({"analytic_account_id": analytic_account.id})
return res
def action_pos_order_invoice(self):
self_ctx = self.with_context(pos_analytic=True)
return super(PosOrder, self_ctx).action_pos_order_invoice()
| 38.173913 | 878 |
516 |
py
|
PYTHON
|
15.0
|
# Copyright 2011-2020 Akretion - Alexis de Lattre
# Copyright 2016-2020 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
{
"name": "Account Analytic Required",
"version": "15.0.1.0.2",
"category": "Analytic Accounting",
"license": "AGPL-3",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["account_usability"],
"data": ["views/account_account_type.xml"],
"installable": True,
}
| 36.857143 | 516 |
7,728 |
py
|
PYTHON
|
15.0
|
# Copyright 2014 Acsone
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from datetime import datetime
from odoo import exceptions
from odoo.tests import common
class TestAccountAnalyticRequired(common.TransactionCase):
@classmethod
def setUpClass(cls):
super(TestAccountAnalyticRequired, cls).setUpClass()
cls.account_obj = cls.env["account.account"]
cls.move_obj = cls.env["account.move"]
cls.move_line_obj = cls.env["account.move.line"]
cls.analytic_account_obj = cls.env["account.analytic.account"]
cls.analytic_account = cls.analytic_account_obj.create({"name": "test aa"})
cls.analytic_account_1 = cls.analytic_account_obj.create(
{"name": "test aa 1 for distribution"}
)
cls.analytic_account_2 = cls.analytic_account_obj.create(
{"name": "test aa 2 for distribution"}
)
cls.analytic_tag_obj = cls.env["account.analytic.tag"]
cls.analytic_distribution_obj = cls.env["account.analytic.distribution"]
cls.account_sales = cls.account_obj.create(
{
"code": "X1020",
"name": "Product Sales - (test)",
"user_type_id": cls.env.ref("account.data_account_type_revenue").id,
}
)
cls.account_recv = cls.account_obj.create(
{
"code": "X11002",
"name": "Debtors - (test)",
"reconcile": True,
"user_type_id": cls.env.ref("account.data_account_type_receivable").id,
}
)
cls.account_exp = cls.account_obj.create(
{
"code": "X2110",
"name": "Expenses - (test)",
"user_type_id": cls.env.ref("account.data_account_type_expenses").id,
}
)
cls.sales_journal = cls.env["account.journal"].create(
{
"name": "Sales Journal - (test)",
"code": "TSAJ",
"type": "sale",
}
)
cls.analytic_tag = cls.analytic_tag_obj.create(
{
"name": "Analytic tag for test",
"company_id": cls.env.company.id,
"active_analytic_distribution": True,
}
)
cls.analytic_tag_wo_distribution = cls.analytic_tag_obj.create(
{"name": "Analytic tag for test 2", "company_id": cls.env.company.id}
)
cls.analytic_distribution_line_1 = cls.analytic_distribution_obj.create(
{
"name": "Analytic distribution line 1",
"account_id": cls.analytic_account_1.id,
"tag_id": cls.analytic_tag.id,
"percentage": 50.0,
}
)
cls.analytic_distribution_line_2 = cls.analytic_distribution_obj.create(
{
"name": "Analytic distribution line 2",
"account_id": cls.analytic_account_1.id,
"tag_id": cls.analytic_tag.id,
"percentage": 50.0,
}
)
def _create_move(self, amount=100, **kwargs):
with_analytic = kwargs.get("with_analytic")
with_analytic_tag = kwargs.get("with_analytic_tag")
date = datetime.now()
ml_obj = self.move_line_obj.with_context(check_move_validity=False)
move_vals = {"name": "/", "journal_id": self.sales_journal.id, "date": date}
move = self.move_obj.create(move_vals)
move_line = ml_obj.create(
{
"move_id": move.id,
"name": "/",
"debit": 0,
"credit": amount,
"account_id": self.account_sales.id,
"analytic_account_id": self.analytic_account.id
if with_analytic
else False,
"analytic_tag_ids": [
(6, 0, [self.analytic_tag.id, self.analytic_tag_wo_distribution.id])
]
if with_analytic_tag
else False,
}
)
ml_obj.create(
{
"move_id": move.id,
"name": "/",
"debit": amount,
"credit": 0,
"account_id": self.account_recv.id,
}
)
return move_line
def _set_analytic_policy(self, policy, account=None):
if account is None:
account = self.account_sales
account.user_type_id.property_analytic_policy = policy
def test_optional(self):
self._set_analytic_policy("optional")
self._create_move(with_analytic=False)
self._create_move(with_analytic=True)
def test_always_no_analytic(self):
self._set_analytic_policy("always")
with self.assertRaises(exceptions.ValidationError):
self._create_move(with_analytic=False)
def test_always_no_analytic_0(self):
# accept missing analytic account when debit=credit=0
self._set_analytic_policy("always")
self._create_move(with_analytic=False, amount=0)
def test_always_with_analytic(self):
self._set_analytic_policy("always")
self._create_move(with_analytic=True)
def test_never_no_analytic(self):
self._set_analytic_policy("never")
self._create_move(with_analytic=False)
def test_never_with_analytic(self):
self._set_analytic_policy("never")
with self.assertRaises(exceptions.ValidationError):
self._create_move(with_analytic=True)
def test_never_with_analytic_0(self):
# accept analytic when debit=credit=0
self._set_analytic_policy("never")
self._create_move(with_analytic=True, amount=0)
def test_always_remove_analytic(self):
# remove analytic when policy is always
self._set_analytic_policy("always")
line = self._create_move(with_analytic=True)
with self.assertRaises(exceptions.ValidationError):
line.write({"analytic_account_id": False})
def test_change_account(self):
self._set_analytic_policy("always", account=self.account_exp)
line = self._create_move(with_analytic=False)
# change account to a_expense with policy always but missing
# analytic_account
with self.assertRaises(exceptions.ValidationError):
line.write({"account_id": self.account_exp.id})
# change account to a_expense with policy always
# with analytic account -> ok
line.write(
{
"account_id": self.account_exp.id,
"analytic_account_id": self.analytic_account.id,
}
)
def test_posted_raise(self):
self._set_analytic_policy("posted")
line = self._create_move(with_analytic=False)
move = line.move_id
with self.assertRaises(exceptions.ValidationError):
move.action_post()
def test_posted_ok(self):
self._set_analytic_policy("posted")
line = self._create_move(with_analytic=True)
move = line.move_id
move.action_post()
self.assertEqual(move.state, "posted")
def test_exception_policy_for_analytic_distribution(self):
self._set_analytic_policy("always")
self._create_move(with_analytic=False, with_analytic_tag=True)
self._set_analytic_policy("posted")
line = self._create_move(with_analytic=False, with_analytic_tag=True)
line.move_id.action_post()
self._set_analytic_policy("never")
with self.assertRaises(exceptions.ValidationError), self.cr.savepoint():
self._create_move(with_analytic=False, with_analytic_tag=True)
| 38.64 | 7,728 |
4,759 |
py
|
PYTHON
|
15.0
|
# Copyright 2011-2020 Akretion - Alexis de Lattre
# Copyright 2016-2020 Camptocamp SA
# Copyright 2020 Druidoo - Iván Todorovich
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo import _, api, exceptions, fields, models
class AccountAccountType(models.Model):
_inherit = "account.account.type"
property_analytic_policy = fields.Selection(
selection=[
("optional", "Optional"),
("always", "Always"),
("posted", "Posted moves"),
("never", "Never"),
],
string="Policy for analytic account",
default="optional",
company_dependent=True,
help=(
"Sets the policy for analytic accounts.\n"
"If you select:\n"
"- Optional: The accountant is free to put an analytic account "
"on an account move line with this type of account.\n"
"- Always: The accountant will get an error message if "
"there is no analytic account.\n"
"- Posted moves: The accountant will get an error message if no "
"analytic account is defined when the move is posted.\n"
"- Never: The accountant will get an error message if an analytic "
"account is present.\n\n"
"This field is company dependent."
),
)
class AccountAccount(models.Model):
_inherit = "account.account"
def _get_analytic_policy(self):
"""Extension point to obtain analytic policy for an account"""
self.ensure_one()
return self.user_type_id.with_company(
self.company_id.id
).property_analytic_policy
class AccountMove(models.Model):
_inherit = "account.move"
def _post(self, soft=True):
res = super()._post(soft=soft)
self.mapped("line_ids")._check_analytic_required()
return res
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
def _has_analytic_distribution(self):
# If the move line has an analytic tag with distribution, the field
# analytic_account_id may be empty. So in this case, we do not check it.
tags_with_analytic_distribution = self.analytic_tag_ids.filtered(
"active_analytic_distribution"
)
return bool(tags_with_analytic_distribution.analytic_distribution_ids)
def _check_analytic_required_msg(self):
self.ensure_one()
company_cur = self.company_currency_id
if company_cur.is_zero(self.debit) and company_cur.is_zero(self.credit):
return None
analytic_policy = self.account_id._get_analytic_policy()
if (
analytic_policy == "always"
and not self.analytic_account_id
and not self._has_analytic_distribution()
):
return _(
"Analytic policy is set to 'Always' with account "
"'%(account)s' but the analytic account is missing in "
"the account move line with label '%(move)s'."
) % {
"account": self.account_id.display_name,
"move": self.name or "",
}
elif analytic_policy == "never" and (
self.analytic_account_id or self._has_analytic_distribution()
):
analytic_account = (
self.analytic_account_id
or self.analytic_tag_ids.analytic_distribution_ids[:1]
)
return _(
"Analytic policy is set to 'Never' with account "
"'%(account)s' but the account move line with label '%(move)s' "
"has an analytic account '%(analytic_account)s'."
) % {
"account": self.account_id.display_name,
"move": self.name or "",
"analytic_account": analytic_account.display_name,
}
elif (
analytic_policy == "posted"
and not self.analytic_account_id
and self.move_id.state == "posted"
and not self._has_analytic_distribution()
):
return _(
"Analytic policy is set to 'Posted moves' with "
"account '%(account)s' but the analytic account is missing "
"in the account move line with label '%(move)s'."
) % {
"account": self.account_id.display_name,
"move": self.name or "",
}
return None
@api.constrains("analytic_account_id", "account_id", "debit", "credit")
def _check_analytic_required(self):
for rec in self:
message = rec._check_analytic_required_msg()
if message:
raise exceptions.ValidationError(message)
| 38.064 | 4,758 |
839 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 ForgeFlow - Jordi Ballester Alomar
# Copyright 2015 Pedro M. Baeza - Antiun Ingeniería
# Copyright 2021 Daniel Reis - Open Source Integrators
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
"name": "Analytic for manufacturing",
"summary": "Adds the analytic account to the production order",
"version": "15.0.1.0.0",
"category": "Manufacturing",
"author": "ForgeFlow, "
"Antiun Ingeniería, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
"José L. Sandoval A., "
"Open Source Integrators, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"license": "AGPL-3",
"depends": ["mrp", "analytic", "stock_account"],
"data": ["views/mrp_view.xml", "views/analytic_account_view.xml"],
"installable": True,
}
| 38 | 836 |
2,318 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Pedro M. Baeza - Antiun Ingeniería
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.tests import common
class TestMrpAnalytic(common.TransactionCase):
def setUp(self):
super(TestMrpAnalytic, self).setUp()
self.analytic_account = self.env["account.analytic.account"].create(
{"name": "Analytic account test"}
)
self.product_category = self.env.ref("product.product_category_all")
self.product_category.write(
{"property_cost_method": "standard", "property_valuation": "real_time"}
)
self.product = self.env["product.product"].create(
{
"name": "Test product",
"type": "product",
"categ_id": self.product_category.id,
"standard_price": 2.0,
}
)
self.raw = self.env["product.product"].create(
{
"name": "Raw material",
"type": "product",
"categ_id": self.product_category.id,
"standard_price": 1.0,
}
)
self.bom = self.env["mrp.bom"].create(
{
"product_id": self.product.id,
"product_tmpl_id": self.product.product_tmpl_id.id,
"bom_line_ids": [(0, 0, {"product_id": self.raw.id, "product_qty": 1})],
}
)
self.production = (
self.env["mrp.production"]
.with_context(import_file=True)
.create(
{
"product_id": self.product.id,
"analytic_account_id": self.analytic_account.id,
"qty_producing": 1,
"product_uom_id": self.product.uom_id.id,
"bom_id": self.bom.id,
}
)
)
self.production.move_raw_ids.write({"quantity_done": 1})
def test_num_productions(self):
self.assertEqual(self.analytic_account.num_productions, 1)
def test_carry_to_move_line(self):
self.production.button_mark_done()
account_moves = self.env["account.move.line"].search(
[("analytic_account_id", "=", self.analytic_account.id)]
)
self.assertEqual(len(account_moves), 4)
| 36.777778 | 2,317 |
1,095 |
py
|
PYTHON
|
15.0
|
# Copyright (C) 2021 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class StockMove(models.Model):
_inherit = "stock.move"
def _generate_valuation_lines_data(
self,
partner_id,
qty,
debit_value,
credit_value,
debit_account_id,
credit_account_id,
description,
):
"""
Ensure Analytic Account is set on the journal items.
Self is a singleton.
"""
rslt = super()._generate_valuation_lines_data(
partner_id,
qty,
debit_value,
credit_value,
debit_account_id,
credit_account_id,
description,
)
analytic = (
self.raw_material_production_id.analytic_account_id
or self.production_id.analytic_account_id
)
for entry in rslt.values():
if not entry.get("analytic_account_id") and analytic:
entry["analytic_account_id"] = analytic.id
return rslt
| 26.707317 | 1,095 |
344 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 ForgeFlow - Jordi Ballester Alomar
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import fields, models
class MrpProduction(models.Model):
_inherit = "mrp.production"
analytic_account_id = fields.Many2one(
comodel_name="account.analytic.account", string="Analytic Account"
)
| 28.666667 | 344 |
594 |
py
|
PYTHON
|
15.0
|
# Copyright 2015 Pedro M. Baeza - Antiun Ingeniería
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import fields, models
class AnalyticAccount(models.Model):
_inherit = "account.analytic.account"
def _compute_num_productions(self):
production = self.env["mrp.production"]
for analytic_account in self:
domain = [("analytic_account_id", "=", analytic_account.id)]
analytic_account.num_productions = production.search_count(domain)
num_productions = fields.Integer(compute=_compute_num_productions, default=0)
| 37.0625 | 593 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.