Skip to content

Commit

Permalink
Merge 2dbac16 into 7526c9d
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed May 21, 2019
2 parents 7526c9d + 2dbac16 commit 32648e4
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 0 deletions.
84 changes: 84 additions & 0 deletions account_fiscal_position_type/README.rst
@@ -0,0 +1,84 @@
==============================
Account Fiscal Position - Type
==============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-legalsylvain%2Faccount--fiscal--rule-lightgray.png?logo=github
:target: https://github.com/legalsylvain/account-fiscal-rule/tree/8.0_ADD_account_fiscal_position_type/account_fiscal_position_type
:alt: legalsylvain/account-fiscal-rule

|badge1| |badge2| |badge3|

This module extends the functionality of account to add a use type on
fiscal position. (``sale``, ``purchase`` or ``all``) to restrict the
usage of fiscal position for out or in invoices.

If a fiscal position is configured for sale, it will not be possible to use
it in a purchase invoice.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure this module, you need to:

* Go to Invoicing / Configuration / Taxes / Fiscal Positions

* On a fiscal position, set the correct settings.

.. figure:: https://raw.githubusercontent.com/legalsylvain/account-fiscal-rule/8.0_ADD_account_fiscal_position_type/account_fiscal_position_type/static/description/fiscal_position_form.png


Note:

It is possible to set the value on the fiscal position templates. In that
case, installing a new chart of account will configure correctly the fiscal
positions.

Known issues / Roadmap
======================

* limit the possibility to set a purchase / sale fiscal position on customer
/ seller.

* Fiscal position template mecanism only works if this patch
https://github.com/OCA/OCB/pull/850 is included.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/legalsylvain/account-fiscal-rule/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/legalsylvain/account-fiscal-rule/issues/new?body=module:%20account_fiscal_position_type%0Aversion:%208.0_ADD_account_fiscal_position_type%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* GRAP

Maintainers
~~~~~~~~~~~

This module is part of the `legalsylvain/account-fiscal-rule <https://github.com/legalsylvain/account-fiscal-rule/tree/8.0_ADD_account_fiscal_position_type/account_fiscal_position_type>`_ project on GitHub.

You are welcome to contribute.
2 changes: 2 additions & 0 deletions account_fiscal_position_type/__init__.py
@@ -0,0 +1,2 @@
# coding: utf-8
from . import models
28 changes: 28 additions & 0 deletions account_fiscal_position_type/__openerp__.py
@@ -0,0 +1,28 @@
# coding: utf-8
# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
'name': 'Account Fiscal Position - Type',
'summary': 'Add sale / purchase type on fiscal position',
'version': '8.0.1.0.0',
'category': 'Accounting',
'author': 'GRAP,Odoo Community Association (OCA)',
'website': 'https://odoo-community.org/',
'license': 'AGPL-3',
'development_status': 'Beta',
'depends': [
'account',
],
'data': [
'views/view_account_fiscal_position.xml',
'views/view_account_fiscal_position_template.xml',
],
'demo': [
'demo/res_groups.xml',
],
'images': [
'static/description/fiscal_position_form.png',
],
}
8 changes: 8 additions & 0 deletions account_fiscal_position_type/demo/res_groups.xml
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="account.group_account_manager" model="res.groups">
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
</data>
</openerp>
4 changes: 4 additions & 0 deletions account_fiscal_position_type/models/__init__.py
@@ -0,0 +1,4 @@
# coding: utf-8
from . import account_fiscal_position
from . import account_fiscal_position_template
from . import account_invoice
37 changes: 37 additions & 0 deletions account_fiscal_position_type/models/account_fiscal_position.py
@@ -0,0 +1,37 @@
# coding: utf-8
# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from openerp import api, fields, models


class AccountFiscalPosition(models.Model):
_inherit = 'account.fiscal.position'

_TYPE_POSITION_USE_SELECTION = [
('sale', 'Sale'),
('purchase', 'Purchase'),
('all', 'All'),
]

type_position_use = fields.Selection(
string='Position Application',
selection=_TYPE_POSITION_USE_SELECTION, default='all')

@api.model
def create(self, values):
AccountFiscalPositionTemplate =\
self.env['account.fiscal.position.template']
chart_template_id = self.env.context.get('chart_template_id', False)
if chart_template_id:
templates = AccountFiscalPositionTemplate.search([
('chart_template_id', '=', chart_template_id),
('name', '=', values['name'])])

if len(templates) == 1:
values.update({
'type_position_use': templates[0].type_position_use,
})
return super(AccountFiscalPosition, self).create(values)
@@ -0,0 +1,30 @@
# coding: utf-8
# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from openerp import api, fields, models


class AccountFiscalPositionTemplate(models.Model):
_inherit = 'account.fiscal.position.template'

_TYPE_POSITION_USE_SELECTION = [
('sale', 'Sale'),
('purchase', 'Purchase'),
('all', 'All'),
]

type_position_use = fields.Selection(
string='Position Application',
selection=_TYPE_POSITION_USE_SELECTION, default='all')

@api.model
def generate_fiscal_position(
self, chart_temp_id, tax_template_ref, acc_template_ref,
company_id):
return super(AccountFiscalPositionTemplate, self.with_context(
chart_template_id=chart_temp_id)).generate_fiscal_position(
chart_temp_id, tax_template_ref, acc_template_ref,
company_id)
54 changes: 54 additions & 0 deletions account_fiscal_position_type/models/account_invoice.py
@@ -0,0 +1,54 @@
# coding: utf-8
# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from openerp import api, fields, models


class AccountInvoice(models.Model):
_inherit = 'account.invoice'

@api.model
def _get_domain_fiscal_position(self, type, partner_id):
if type in ['out_invoice', 'out_refund']:
return [('type_position_use', 'in', ['sale', 'all'])]
elif type in ['in_invoice', 'in_refund']:
return [('type_position_use', 'in', ['purchase', 'all'])]

@api.multi
def onchange_partner_id(
self, type, partner_id, date_invoice=False,
payment_term=False, partner_bank_id=False, company_id=False):
AccountFiscalPosition = self.env['account.fiscal.position']
res = super(AccountInvoice, self).onchange_partner_id(
type, partner_id, date_invoice=date_invoice,
payment_term=payment_term, partner_bank_id=partner_bank_id,
company_id=company_id)
if 'domain' not in res:
res['domain'] = {}
if 'value' not in res:
res['value'] = {}

domain = self._get_domain_fiscal_position(
type, partner_id)
res['domain']['fiscal_position'] = str(domain)

fiscal_position_id = res['value'].get('fiscal_position', False)
if not fiscal_position_id:
return res

allow_fiscal_position_ids = AccountFiscalPosition.search(domain)
if fiscal_position_id not in allow_fiscal_position_ids.ids:
res['value']['fiscal_position'] = False

return res

fiscal_position = fields.Many2one(
domain="[('type_position_use', 'in', {"
"'out_invoice': ['sale', 'all'],"
"'out_refund': ['sale', 'all'],"
"'in_refund': ['purchase', 'all'],"
"'in_invoice': ['purchase', 'all']}"
".get(type, []))]")
14 changes: 14 additions & 0 deletions account_fiscal_position_type/readme/CONFIGURE.rst
@@ -0,0 +1,14 @@
To configure this module, you need to:

* Go to Invoicing / Configuration / Taxes / Fiscal Positions

* On a fiscal position, set the correct settings.

.. figure:: ../static/description/fiscal_position_form.png


Note:

It is possible to set the value on the fiscal position templates. In that
case, installing a new chart of account will configure correctly the fiscal
positions.
6 changes: 6 additions & 0 deletions account_fiscal_position_type/readme/DESCRIPTION.rst
@@ -0,0 +1,6 @@
This module extends the functionality of account to add a use type on
fiscal position. (``sale``, ``purchase`` or ``all``) to restrict the
usage of fiscal position for out or in invoices.

If a fiscal position is configured for sale, it will not be possible to use
it in a purchase invoice.
5 changes: 5 additions & 0 deletions account_fiscal_position_type/readme/ROADMAP.rst
@@ -0,0 +1,5 @@
* limit the possibility to set a purchase / sale fiscal position on customer
/ seller.

* Fiscal position template mecanism only works if this patch
https://github.com/OCA/OCB/pull/850 is included.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions account_fiscal_position_type/tests/__init__.py
@@ -0,0 +1,2 @@
# coding: utf-8
from . import test_module
49 changes: 49 additions & 0 deletions account_fiscal_position_type/tests/test_module.py
@@ -0,0 +1,49 @@
# coding: utf-8
# Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.tests.common import TransactionCase


class Tests(TransactionCase):

def setUp(self):
super(Tests, self).setUp()
self.AccountFiscalPosition = self.env['account.fiscal.position']
self.WizardChart = self.env['wizard.multi.charts.accounts']
self.coa = self.env.ref('account.configurable_chart_template')
self.fpt_normal_tax = self.env.ref(
'account.fiscal_position_normal_taxes_template1')
self.fpt_tax_exempt = self.env.ref(
'account.fiscal_position_tax_exempt_template2')
self.company = self.env.ref('base.main_company')

# Test Section
# Test disabled because it requires this patch
# https://github.com/OCA/OCB/pull/850
# TODO-V10. In new full API, enable this test.
def _disabled_test_template(self):
wizard = self.WizardChart.create({
'company_id': self.company.id,
'chart_template_id': self.coa.id,
'code_digits': 6,
'currency_id': self.company.currency_id.id,
})
self.fpt_normal_tax.type_position_use = 'purchase'
self.fpt_tax_exempt.type_position_use = 'sale'
wizard.execute()

fp_normal_taxes = self.AccountFiscalPosition.search([
('name', '=', self.fpt_normal_tax.name),
('type_position_use', '=', 'purchase')])
self.AssertEqual(
len(fp_normal_taxes), 1,
"Correct Creation of 'purchase' Fiscal Position failed")

fp_tax_exempt = self.AccountFiscalPosition.search([
('name', '=', self.fpt_tax_exempt.name),
('type_position_use', '=', 'sale')])
self.AssertEqual(
len(fp_tax_exempt), 1,
"Correct Creation of 'sale' Fiscal Position failed")
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<openerp><data>

<record id="view_account_fiscal_position_form" model="ir.ui.view">
<field name="model">account.fiscal.position</field>
<field name="inherit_id" ref="account.view_account_position_form"/>
<field name="arch" type="xml">
<field name="active" position="before">
<field name="type_position_use"/>
</field>
</field>
</record>

<record id="view_account_fiscal_position_tree" model="ir.ui.view">
<field name="model">account.fiscal.position</field>
<field name="inherit_id" ref="account.view_account_position_tree"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="type_position_use"/>
</field>
</field>
</record>

</data></openerp>
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<openerp><data>

<record id="view_account_fiscal_position_template_form" model="ir.ui.view">
<field name="model">account.fiscal.position.template</field>
<field name="inherit_id" ref="account.view_account_position_template_form"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="type_position_use"/>
</field>
</field>
</record>

<record id="view_account_fiscal_position_template_tree" model="ir.ui.view">
<field name="model">account.fiscal.position.template</field>
<field name="inherit_id" ref="account.view_account_position_template_tree"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="type_position_use"/>
</field>
</field>
</record>

</data></openerp>

0 comments on commit 32648e4

Please sign in to comment.