Skip to content

Commit

Permalink
[IMP] cooperator: Add specific income account for share increase
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasramossomit committed Oct 31, 2024
1 parent bd9d47c commit 070f996
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 8 deletions.
6 changes: 5 additions & 1 deletion cooperator/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Cooperators
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:fc9abf44c53ec9ed50ac717e7fa26489ddc8765fd713c8db92f40bc077d5b1ce
!! source digest: sha256:4adbd8d94496075c68a7aa4ac052869f770abfc54315cb337d0d77536d4980ea
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -267,6 +267,10 @@ Contributors
* Carmen Bianca Bakker
* hugues de keyzer

* 'Som IT Cooperatiu SCCL'

* Nicolás Ramos

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

Expand Down
1 change: 1 addition & 0 deletions cooperator/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"views/operation_request_view.xml",
"views/account_move_views.xml",
"views/product_view.xml",
"views/product_category_view.xml",
"views/res_company_view.xml",
"views/account_journal_views.xml",
"views/cooperative_membership_view.xml",
Expand Down
1 change: 1 addition & 0 deletions cooperator/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
from . import share_line
from . import subscription_register
from . import subscription_request
from . import product_category
12 changes: 12 additions & 0 deletions cooperator/models/product_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import fields, models

class ProductCategory(models.Model):
_inherit = 'product.category'

property_account_income_increase_categ_id = fields.Many2one(
'account.account',
company_dependent=True,
string="Income Account for Share Increase",
domain="[('deprecated', '=', False), ('company_id', '=', current_company_id)]",
help="This account will be used when validating a share increase subscription request instead of the default income account"
)
7 changes: 7 additions & 0 deletions cooperator/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class ProductTemplate(models.Model):
by_company = fields.Boolean(string="Can be subscribed by companies?")
by_individual = fields.Boolean(string="Can be subscribed by individuals?")
mail_template = fields.Many2one("mail.template", string="Mail template")
property_account_income_increase_id = fields.Many2one(
'account.account',
company_dependent=True,
string="Income Account for Share Increase",
domain="[('deprecated', '=', False), ('company_id', '=', current_company_id)]",
help="This account will be used when validating a share increase subscription request instead of the default income account"
)

def get_web_share_products(self, is_company):
if is_company is True:
Expand Down
18 changes: 14 additions & 4 deletions cooperator/models/subscription_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,20 @@ def _prepare_invoice_line(self, move_id, product, partner, qty):
# request for a company other than the current one, which can happen
# when a user is "logged in" to multiple companies.
product = product.with_company(self.company_id)
account = (
product.property_account_income_id
or product.categ_id.property_account_income_categ_id
)

if self.type == 'increase':
account = (
product.property_account_income_increase_id
or product.categ_id.property_account_income_increase_categ_id
or product.property_account_income_id
or product.categ_id.property_account_income_categ_id
)
else:
account = (
product.property_account_income_id
or product.categ_id.property_account_income_categ_id
)

if not account:
raise UserError(
_(
Expand Down
4 changes: 4 additions & 0 deletions cooperator/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
* Manuel Claeys Bouuaert
* Carmen Bianca Bakker
* hugues de keyzer

* 'Som IT Cooperatiu SCCL'

* Nicolás Ramos
6 changes: 5 additions & 1 deletion cooperator/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Cooperators</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:fc9abf44c53ec9ed50ac717e7fa26489ddc8765fd713c8db92f40bc077d5b1ce
!! source digest: sha256:4adbd8d94496075c68a7aa4ac052869f770abfc54315cb337d0d77536d4980ea
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/cooperative/tree/16.0/cooperator"><img alt="OCA/cooperative" src="https://img.shields.io/badge/github-OCA%2Fcooperative-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/cooperative-16-0/cooperative-16-0-cooperator"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/cooperative&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Manage cooperators of a cooperative.</p>
Expand Down Expand Up @@ -611,6 +611,10 @@ <h2><a class="toc-backref" href="#toc-entry-14">Contributors</a></h2>
<li>hugues de keyzer</li>
</ul>
</li>
<li>‘Som IT Cooperatiu SCCL’<ul>
<li>Nicolás Ramos</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
41 changes: 40 additions & 1 deletion cooperator/tests/test_cooperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ def test_create_cooperator_and_user_for_multiple_companies(self):
self.validate_subscription_request_and_pay(subscription_request_2)
partner_2 = subscription_request_2.partner_id
self.assertEqual(partner_1, partner_2)
user = self.env["res.users"].search([("partner_id", "=", partner_1.id)])
self.assertEqual(user.company_id, self.company)
self.assertEqual(user.company_ids, self.company | company_2)

Expand Down Expand Up @@ -1584,3 +1583,43 @@ def test_create_user_multiple_users(self):
self.assertEqual(inactive_user.company_ids, self.env.company)
self.assertEqual(inactive_user.company_id, self.env.company)
self.assertTrue(inactive_user.active)

def test_capital_release_request_income_account_new(self):
"""
Test that the income account of capital release requests for new subscriptions
uses the standard income account.
"""
self.subscription_request_1.validate_subscription_request()
invoice = self.subscription_request_1.capital_release_request
income_line = invoice.invoice_line_ids.filtered(lambda l: l.credit == 0)
self.assertEqual(
income_line.account_id,
self.share_y.property_account_income_id
or self.share_y.categ_id.property_account_income_categ_id,
)

def test_capital_release_request_income_account_increase(self):
"""
Test that the income account of capital release requests for increase subscriptions
uses the increase income account.
"""
self.subscription_request_1.validate_subscription_request()
self.pay_invoice(self.subscription_request_1.capital_release_request)

subscription_request_2 = self.create_dummy_subscription_from_partner(
self.subscription_request_1.partner_id
)

increase_account = self.env["account.account"].create(
{
"name": "Test Increase Income Account",
"code": "TINC",
"account_type": "income",
}
)

self.share_y.property_account_income_increase_id = increase_account.id
subscription_request_2.validate_subscription_request()
invoice = subscription_request_2.capital_release_request
income_line = invoice.invoice_line_ids.filtered(lambda l: l.credit == 0)
self.assertEqual(income_line.account_id, increase_account)
14 changes: 14 additions & 0 deletions cooperator/views/product_category_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_category_form_view_account_inherit" model="ir.ui.view">
<field name="name">product.category.form.account.inherit</field>
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='property_account_income_categ_id']" position="after">
<field name="property_account_income_increase_categ_id"
groups="account.group_account_readonly"/>
</xpath>
</field>
</record>
</odoo>
5 changes: 4 additions & 1 deletion cooperator/views/product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ SPDX-License-Identifier: AGPL-3.0-or-later
<label for="display_on_website" />
</div>
</xpath>
<xpath expr="//field[@name='property_account_income_id']" position="after">
<field name="property_account_income_increase_id"
groups="account.group_account_readonly"/>
</xpath>
<page name="general_information" position="after">
<page
string="Share Information"
Expand Down Expand Up @@ -180,5 +184,4 @@ SPDX-License-Identifier: AGPL-3.0-or-later
</p>
</field>
</record> -->

</odoo>

0 comments on commit 070f996

Please sign in to comment.