mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[IMP] : black, isort, prettier
This commit is contained in:
@@ -2,25 +2,22 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Costcenter',
|
||||
'summary': 'Cost center information for invoice lines',
|
||||
'author': 'Onestein, Odoo Community Association (OCA)',
|
||||
'license': 'AGPL-3',
|
||||
'website': 'https://github.com/OCA/account-financial-tools/',
|
||||
'category': 'Accounting',
|
||||
'version': '12.0.1.0.0',
|
||||
'depends': [
|
||||
'account',
|
||||
'base_view_inheritance_extension'
|
||||
"name": "Costcenter",
|
||||
"summary": "Cost center information for invoice lines",
|
||||
"author": "Onestein, Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"website": "https://github.com/OCA/account-financial-tools",
|
||||
"category": "Accounting",
|
||||
"version": "12.0.1.0.0",
|
||||
"depends": ["account", "base_view_inheritance_extension"],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"security/account_cost_center_security.xml",
|
||||
"views/account_cost_center.xml",
|
||||
"views/account_move.xml",
|
||||
"views/account_move_line.xml",
|
||||
"views/account_invoice.xml",
|
||||
"views/account_invoice_report.xml",
|
||||
],
|
||||
'data': [
|
||||
'security/ir.model.access.csv',
|
||||
'security/account_cost_center_security.xml',
|
||||
'views/account_cost_center.xml',
|
||||
'views/account_move.xml',
|
||||
'views/account_move_line.xml',
|
||||
'views/account_invoice.xml',
|
||||
'views/account_invoice_report.xml',
|
||||
],
|
||||
'installable': True,
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -5,13 +5,11 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class AccountCostCenter(models.Model):
|
||||
_name = 'account.cost.center'
|
||||
_description = 'Account Cost Center'
|
||||
_name = "account.cost.center"
|
||||
_description = "Account Cost Center"
|
||||
|
||||
name = fields.Char(string='Title', required=True)
|
||||
name = fields.Char(string="Title", required=True)
|
||||
code = fields.Char(required=True)
|
||||
company_id = fields.Many2one(
|
||||
'res.company',
|
||||
string='Company',
|
||||
default=lambda self: self.env.user.company_id
|
||||
"res.company", string="Company", default=lambda self: self.env.user.company_id
|
||||
)
|
||||
|
||||
@@ -5,21 +5,21 @@ from odoo import api, fields, models
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = 'account.invoice'
|
||||
_inherit = "account.invoice"
|
||||
|
||||
cost_center_id = fields.Many2one(
|
||||
'account.cost.center',
|
||||
string='Cost Center',
|
||||
"account.cost.center",
|
||||
string="Cost Center",
|
||||
readonly=True,
|
||||
states={'draft': [('readonly', False)]},
|
||||
help='Default Cost Center',
|
||||
states={"draft": [("readonly", False)]},
|
||||
help="Default Cost Center",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def line_get_convert(self, line, part):
|
||||
res = super(AccountInvoice, self).line_get_convert(line, part)
|
||||
if line.get('cost_center_id'):
|
||||
res['cost_center_id'] = line['cost_center_id']
|
||||
if line.get("cost_center_id"):
|
||||
res["cost_center_id"] = line["cost_center_id"]
|
||||
return res
|
||||
|
||||
@api.model
|
||||
@@ -27,9 +27,9 @@ class AccountInvoice(models.Model):
|
||||
res = super(AccountInvoice, self).invoice_line_move_line_get()
|
||||
|
||||
for dict_data in res:
|
||||
invl_id = dict_data.get('invl_id')
|
||||
line = self.env['account.invoice.line'].browse(invl_id)
|
||||
invl_id = dict_data.get("invl_id")
|
||||
line = self.env["account.invoice.line"].browse(invl_id)
|
||||
if line.cost_center_id:
|
||||
dict_data['cost_center_id'] = line.cost_center_id.id
|
||||
dict_data["cost_center_id"] = line.cost_center_id.id
|
||||
|
||||
return res
|
||||
|
||||
@@ -5,16 +5,17 @@ from odoo import api, fields, models
|
||||
|
||||
|
||||
class AccountInvoiceLine(models.Model):
|
||||
_inherit = 'account.invoice.line'
|
||||
_inherit = "account.invoice.line"
|
||||
|
||||
@api.model
|
||||
def _default_cost_center(self):
|
||||
return self.env['account.cost.center'].browse(
|
||||
self.env.context.get('cost_center_id'))
|
||||
return self.env["account.cost.center"].browse(
|
||||
self.env.context.get("cost_center_id")
|
||||
)
|
||||
|
||||
cost_center_id = fields.Many2one(
|
||||
'account.cost.center',
|
||||
string='Cost Center',
|
||||
"account.cost.center",
|
||||
string="Cost Center",
|
||||
index=True,
|
||||
default=lambda self: self._default_cost_center(),
|
||||
)
|
||||
|
||||
@@ -5,22 +5,23 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class AccountInvoiceReport(models.Model):
|
||||
_inherit = 'account.invoice.report'
|
||||
_inherit = "account.invoice.report"
|
||||
|
||||
cost_center_id = fields.Many2one(
|
||||
'account.cost.center',
|
||||
string='Cost Center',
|
||||
readonly=True
|
||||
"account.cost.center", string="Cost Center", readonly=True
|
||||
)
|
||||
|
||||
def _select(self):
|
||||
return super(AccountInvoiceReport, self)._select() + \
|
||||
", sub.cost_center_id as cost_center_id"
|
||||
return (
|
||||
super(AccountInvoiceReport, self)._select()
|
||||
+ ", sub.cost_center_id as cost_center_id"
|
||||
)
|
||||
|
||||
def _sub_select(self):
|
||||
return super(AccountInvoiceReport, self)._sub_select() + \
|
||||
", ail.cost_center_id as cost_center_id"
|
||||
return (
|
||||
super(AccountInvoiceReport, self)._sub_select()
|
||||
+ ", ail.cost_center_id as cost_center_id"
|
||||
)
|
||||
|
||||
def _group_by(self):
|
||||
return super(AccountInvoiceReport, self)._group_by() + \
|
||||
", ail.cost_center_id"
|
||||
return super(AccountInvoiceReport, self)._group_by() + ", ail.cost_center_id"
|
||||
|
||||
@@ -5,10 +5,8 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
_inherit = "account.move.line"
|
||||
|
||||
cost_center_id = fields.Many2one(
|
||||
'account.cost.center',
|
||||
index=True,
|
||||
string='Cost Center'
|
||||
"account.cost.center", index=True, string="Cost Center"
|
||||
)
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="account_cost_center_comp_rule" model="ir.rule">
|
||||
<field name="name">Cost center multi company rule</field>
|
||||
<field name="model_id" ref="account_cost_center.model_account_cost_center"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
<field
|
||||
name="model_id"
|
||||
ref="account_cost_center.model_account_cost_center"
|
||||
/>
|
||||
<field name="global" eval="True" />
|
||||
<field
|
||||
name="domain_force"
|
||||
>['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
|
||||
</record>
|
||||
</data>
|
||||
|
||||
|
||||
@@ -5,71 +5,88 @@ from odoo.tests import common
|
||||
|
||||
|
||||
class TestAccountCostCenter(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAccountCostCenter, self).setUp()
|
||||
|
||||
acc_rec = self.env.ref('account.data_account_type_receivable')
|
||||
acc_exp = self.env.ref('account.data_account_type_expenses')
|
||||
self.invoice_account = self.env['account.account'].search([
|
||||
('user_type_id', '=', acc_rec.id)
|
||||
], limit=1).id
|
||||
self.invoice_line_account = self.env['account.account'].search([
|
||||
('user_type_id', '=', acc_exp.id)],
|
||||
limit=1).id
|
||||
acc_rec = self.env.ref("account.data_account_type_receivable")
|
||||
acc_exp = self.env.ref("account.data_account_type_expenses")
|
||||
self.invoice_account = (
|
||||
self.env["account.account"]
|
||||
.search([("user_type_id", "=", acc_rec.id)], limit=1)
|
||||
.id
|
||||
)
|
||||
self.invoice_line_account = (
|
||||
self.env["account.account"]
|
||||
.search([("user_type_id", "=", acc_exp.id)], limit=1)
|
||||
.id
|
||||
)
|
||||
|
||||
self.invoice1 = self.env['account.invoice'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_2').id,
|
||||
'account_id': self.invoice_account,
|
||||
'type': 'in_invoice',
|
||||
})
|
||||
self.invoice1 = self.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": self.env.ref("base.res_partner_2").id,
|
||||
"account_id": self.invoice_account,
|
||||
"type": "in_invoice",
|
||||
}
|
||||
)
|
||||
|
||||
self.line1 = self.env['account.invoice.line'].create({
|
||||
'product_id': self.env.ref('product.product_product_2').id,
|
||||
'quantity': 1.0,
|
||||
'price_unit': 100.0,
|
||||
'invoice_id': self.invoice1.id,
|
||||
'name': 'product that cost 100',
|
||||
'account_id': self.invoice_line_account,
|
||||
})
|
||||
self.line1 = self.env["account.invoice.line"].create(
|
||||
{
|
||||
"product_id": self.env.ref("product.product_product_2").id,
|
||||
"quantity": 1.0,
|
||||
"price_unit": 100.0,
|
||||
"invoice_id": self.invoice1.id,
|
||||
"name": "product that cost 100",
|
||||
"account_id": self.invoice_line_account,
|
||||
}
|
||||
)
|
||||
|
||||
self.costcenter = self.env['account.cost.center'].create({
|
||||
'name': 'Cost Center Test',
|
||||
'code': 'CC1',
|
||||
'company_id': self.env.user.company_id.id
|
||||
})
|
||||
self.costcenter = self.env["account.cost.center"].create(
|
||||
{
|
||||
"name": "Cost Center Test",
|
||||
"code": "CC1",
|
||||
"company_id": self.env.user.company_id.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.invoice2 = self.env['account.invoice'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_2').id,
|
||||
'account_id': self.invoice_account,
|
||||
'type': 'in_invoice',
|
||||
'cost_center_id': self.costcenter.id,
|
||||
})
|
||||
self.invoice2 = self.env["account.invoice"].create(
|
||||
{
|
||||
"partner_id": self.env.ref("base.res_partner_2").id,
|
||||
"account_id": self.invoice_account,
|
||||
"type": "in_invoice",
|
||||
"cost_center_id": self.costcenter.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.line2 = self.env['account.invoice.line'].with_context(
|
||||
cost_center_id=self.costcenter.id).create({
|
||||
'product_id': self.env.ref('product.product_product_4').id,
|
||||
'quantity': 1.0,
|
||||
'price_unit': 130.0,
|
||||
'invoice_id': self.invoice2.id,
|
||||
'name': 'product that cost 130',
|
||||
'account_id': self.invoice_line_account,
|
||||
})
|
||||
self.line2 = (
|
||||
self.env["account.invoice.line"]
|
||||
.with_context(cost_center_id=self.costcenter.id)
|
||||
.create(
|
||||
{
|
||||
"product_id": self.env.ref("product.product_product_4").id,
|
||||
"quantity": 1.0,
|
||||
"price_unit": 130.0,
|
||||
"invoice_id": self.invoice2.id,
|
||||
"name": "product that cost 130",
|
||||
"account_id": self.invoice_line_account,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def test_01_check_lines(self):
|
||||
self.assertFalse(
|
||||
self.line1.cost_center_id,
|
||||
"Default cost center per line not set")
|
||||
self.line1.cost_center_id, "Default cost center per line not set"
|
||||
)
|
||||
|
||||
self.assertTrue(
|
||||
(self.line2.cost_center_id == self.costcenter),
|
||||
"Default cost center per line set")
|
||||
"Default cost center per line set",
|
||||
)
|
||||
|
||||
def test_02_confirm_invoice(self):
|
||||
self.invoice2.action_invoice_open()
|
||||
for move in self.invoice2.move_id.line_ids:
|
||||
cost_center = move.cost_center_id
|
||||
if move.name == 'product that cost 130':
|
||||
if move.name == "product that cost 130":
|
||||
self.assertTrue(cost_center)
|
||||
else:
|
||||
self.assertFalse(cost_center)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<!-- Cost Center views -->
|
||||
@@ -9,18 +9,22 @@
|
||||
<sheet>
|
||||
<group>
|
||||
<div class="oe_title">
|
||||
<label for="name"/>
|
||||
<label for="name" />
|
||||
<h1>
|
||||
<field name="name"/>
|
||||
<field name="name" />
|
||||
</h1>
|
||||
</div>
|
||||
</group>
|
||||
<group name="main_group">
|
||||
<group name="main_group1">
|
||||
<field name="code"/>
|
||||
<field name="code" />
|
||||
</group>
|
||||
<group name="main_group2">
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
<field
|
||||
name="company_id"
|
||||
options="{'no_create': True}"
|
||||
groups="base.group_multi_company"
|
||||
/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook name="notebook">
|
||||
@@ -34,9 +38,9 @@
|
||||
<field name="model">account.cost.center</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="code"/>
|
||||
<field name="name"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="code" />
|
||||
<field name="name" />
|
||||
<field name="company_id" groups="base.group_multi_company" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -45,7 +49,11 @@
|
||||
<field name="model">account.cost.center</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="name" string="Name/Code" filter_domain="['|', ('code','ilike', self), ('name','ilike',self)]"/>
|
||||
<field
|
||||
name="name"
|
||||
string="Name/Code"
|
||||
filter_domain="['|', ('code','ilike', self), ('name','ilike',self)]"
|
||||
/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
@@ -56,7 +64,7 @@
|
||||
<field name="res_model">account.cost.center</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="search_view_id" ref="account_cost_center_view_search"/>
|
||||
<field name="search_view_id" ref="account_cost_center_view_search" />
|
||||
<field name="help" type="html">
|
||||
<p class="oe_view_nocontent_create">
|
||||
Click to add a new cost center.
|
||||
@@ -68,10 +76,12 @@
|
||||
</record>
|
||||
|
||||
<!-- Cost Center menu-->
|
||||
<menuitem id="cost_center_menu"
|
||||
parent="account.menu_analytic_accounting"
|
||||
action="account_cost_center_action"
|
||||
groups="account.group_account_user"
|
||||
sequence="40"/>
|
||||
<menuitem
|
||||
id="cost_center_menu"
|
||||
parent="account.menu_analytic_accounting"
|
||||
action="account_cost_center_action"
|
||||
groups="account.group_account_user"
|
||||
sequence="40"
|
||||
/>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,34 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="invoice_form" model="ir.ui.view">
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_form"/>
|
||||
<field name="inherit_id" ref="account.invoice_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="date_invoice" position="after">
|
||||
<field name="cost_center_id"/>
|
||||
<field name="cost_center_id" />
|
||||
</field>
|
||||
<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='account_id']" position="after">
|
||||
<field name="cost_center_id"/>
|
||||
<xpath
|
||||
expr="//field[@name='invoice_line_ids']/tree/field[@name='account_id']"
|
||||
position="after"
|
||||
>
|
||||
<field name="cost_center_id" />
|
||||
</xpath>
|
||||
<field name="invoice_line_ids" position="attributes">
|
||||
<attribute name="context" operation="python_dict" key="cost_center_id">cost_center_id</attribute>
|
||||
<attribute
|
||||
name="context"
|
||||
operation="python_dict"
|
||||
key="cost_center_id"
|
||||
>cost_center_id</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="invoice_supplier_form" model="ir.ui.view">
|
||||
<field name="model">account.invoice</field>
|
||||
<field name="inherit_id" ref="account.invoice_supplier_form"/>
|
||||
<field name="inherit_id" ref="account.invoice_supplier_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="origin" position="after">
|
||||
<field name="cost_center_id"/>
|
||||
<field name="cost_center_id" />
|
||||
</field>
|
||||
<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='account_id']" position="after">
|
||||
<field name="cost_center_id"/>
|
||||
<xpath
|
||||
expr="//field[@name='invoice_line_ids']/tree/field[@name='account_id']"
|
||||
position="after"
|
||||
>
|
||||
<field name="cost_center_id" />
|
||||
</xpath>
|
||||
<field name="invoice_line_ids" position="attributes">
|
||||
<attribute name="context" operation="python_dict" key="cost_center_id">cost_center_id</attribute>
|
||||
<attribute
|
||||
name="context"
|
||||
operation="python_dict"
|
||||
key="cost_center_id"
|
||||
>cost_center_id</attribute>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_account_invoice_report_search" model="ir.ui.view">
|
||||
<field name="model">account.invoice.report</field>
|
||||
<field name="inherit_id" ref="account.view_account_invoice_report_search"/>
|
||||
<field name="inherit_id" ref="account.view_account_invoice_report_search" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group/filter[@name='user']" position="after">
|
||||
<filter string="Cost Center" name="cost_center" context="{'group_by':'cost_center_id'}" />
|
||||
<filter
|
||||
string="Cost Center"
|
||||
name="cost_center"
|
||||
context="{'group_by':'cost_center_id'}"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_move_form" model="ir.ui.view">
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_form"/>
|
||||
<field name="inherit_id" ref="account.view_move_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//notebook//field[@name='line_ids']/tree/field[@name='analytic_account_id']" position="after">
|
||||
<field name="cost_center_id"/>
|
||||
<xpath
|
||||
expr="//notebook//field[@name='line_ids']/tree/field[@name='analytic_account_id']"
|
||||
position="after"
|
||||
>
|
||||
<field name="cost_center_id" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_move_line_form" model="ir.ui.view">
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="inherit_id" ref="account.view_move_line_form"/>
|
||||
<field name="inherit_id" ref="account.view_move_line_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="analytic_account_id" position="after">
|
||||
<field name="cost_center_id"/>
|
||||
<field name="cost_center_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_move_line_tree" model="ir.ui.view">
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="inherit_id" ref="account.view_move_line_tree"/>
|
||||
<field name="inherit_id" ref="account.view_move_line_tree" />
|
||||
<field name="priority">1</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="analytic_account_id" position="after">
|
||||
<field name="cost_center_id"/>
|
||||
<field name="cost_center_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
1
setup/account_cost_center/odoo/addons/account_cost_center
Symbolic link
1
setup/account_cost_center/odoo/addons/account_cost_center
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../account_cost_center
|
||||
6
setup/account_cost_center/setup.py
Normal file
6
setup/account_cost_center/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user