From ee5d5815987abcb3be445aecb2b9913e2f21231e Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Mon, 7 Oct 2019 16:53:51 +0200 Subject: [PATCH 1/6] [REF] emc: move bba fields to easy_my_coop_be --- easy_my_coop/models/coop.py | 49 +++++++++++++++++----------------- easy_my_coop_be/models/coop.py | 17 ++++++++++++ 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/easy_my_coop/models/coop.py b/easy_my_coop/models/coop.py index 8e0c4a1..df95c26 100644 --- a/easy_my_coop/models/coop.py +++ b/easy_my_coop/models/coop.py @@ -445,7 +445,6 @@ class SubscriptionRequest(models.Model): 'city': self.city, 'email': self.company_email, 'out_inv_comm_type': 'bba', 'customer': self.share_product_id.customer, - 'out_inv_comm_algorithm': 'random', 'country_id': self.country_id.id, 'lang': self.lang, 'data_policy_approved': self.data_policy_approved, @@ -459,8 +458,6 @@ class SubscriptionRequest(models.Model): 'zip': self.zip_code, 'email': self.email, 'gender': self.gender, 'cooperator': True, 'city': self.city, 'phone': self.phone, - 'out_inv_comm_type': 'bba', - 'out_inv_comm_algorithm': 'random', 'country_id': self.country_id.id, 'lang': self.lang, 'birthdate_date': self.birthdate, 'customer': self.share_product_id.customer, @@ -469,6 +466,29 @@ class SubscriptionRequest(models.Model): } return partner_vals + def get_representative_vals(self): + contact_vals = { + 'name': self.name, + 'firstname': self.firstname, + 'lastname': self.lastname, 'customer': False, + 'is_company': False, 'cooperator': True, + 'street': self.address, 'gender': self.gender, + 'zip': self.zip_code, 'city': self.city, + 'phone': self.phone, 'email': self.email, + 'country_id': self.country_id.id, + 'out_inv_comm_type': 'bba', + 'out_inv_comm_algorithm': 'random', + 'lang': self.lang, + 'birthdate_date': self.birthdate, + 'parent_id': partner.id, + 'representative': True, + 'function': self.contact_person_function, + 'type': 'representative', + 'data_policy_approved': self.data_policy_approved, + 'internal_rules_approved': self.internal_rules_approved + } + return contact_vals + def create_coop_partner(self): partner_obj = self.env['res.partner'] @@ -526,27 +546,8 @@ class SubscriptionRequest(models.Model): if contact: contact.type = 'representative' if not contact: - contact_vals = { - 'name': self.name, - 'firstname': self.firstname, - 'lastname': self.lastname, 'customer': False, - 'is_company': False, 'cooperator': True, - 'street': self.address, 'gender': self.gender, - 'zip': self.zip_code, 'city': self.city, - 'phone': self.phone, 'email': self.email, - 'country_id': self.country_id.id, - 'out_inv_comm_type': 'bba', - 'out_inv_comm_algorithm': 'random', - 'lang': self.lang, - 'birthdate_date': self.birthdate, - 'parent_id': partner.id, - 'representative': True, - 'function': self.contact_person_function, - 'type': 'representative', - 'data_policy_approved': self.data_policy_approved, - 'internal_rules_approved': self.internal_rules_approved - } - contact = partner_obj.create(contact_vals) + contact_vals = self.get_representative_vals() + partner_obj.create(contact_vals) else: if len(contact) > 1: raise UserError(_('There is two different persons with the' diff --git a/easy_my_coop_be/models/coop.py b/easy_my_coop_be/models/coop.py index ad9108b..f2be562 100644 --- a/easy_my_coop_be/models/coop.py +++ b/easy_my_coop_be/models/coop.py @@ -8,3 +8,20 @@ class SubscriptionRequest(models.Model): ('asbl', 'ASBL'), ('sprl', 'SPRL'), ('sa', 'SA')]) + + def get_partner_company_vals(self): + vals = super(SubscriptionRequest).get_partner_company_vals() + vals['out_inv_comm_algorithm'] = 'random' + return vals + + def get_partner_vals(self): + vals = super(SubscriptionRequest).get_partner_vals() + vals['out_inv_comm_type'] = 'bba' + vals['out_inv_comm_algorithm'] = 'random' + return vals + + def get_representative_valst(self): + vals = super(SubscriptionRequest).get_representative_vals() + vals['out_inv_comm_type'] = 'bba' + vals['out_inv_comm_algorithm'] = 'random' + return vals From c6464dad169f485424fb932cf6abe46aea198d3c Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Mon, 7 Oct 2019 16:54:42 +0200 Subject: [PATCH 2/6] [IMP] emc: add user error if cooperator account is not set --- easy_my_coop/models/coop.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/easy_my_coop/models/coop.py b/easy_my_coop/models/coop.py index df95c26..a88c472 100644 --- a/easy_my_coop/models/coop.py +++ b/easy_my_coop/models/coop.py @@ -404,7 +404,13 @@ class SubscriptionRequest(models.Model): if self.company_id.property_cooperator_account: account = self.company_id.property_cooperator_account else: - account = account_obj.search([('code', '=', '416000')])[0] + accounts = account_obj.search([('code', '=', '416000')]) + if accounts: + account = accounts[0] + else: + raise UserError(_( + 'You must set a cooperator account on you company.' + )) return account def get_invoice_vals(self, partner): From af4e301cdfdc67e5ac364f4edcbfe2c1b69f60eb Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Mon, 7 Oct 2019 16:55:30 +0200 Subject: [PATCH 3/6] [IMP] emc: minor todo and comments --- easy_my_coop/models/partner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/easy_my_coop/models/partner.py b/easy_my_coop/models/partner.py index 85ba9f3..ea61b35 100644 --- a/easy_my_coop/models/partner.py +++ b/easy_my_coop/models/partner.py @@ -87,7 +87,7 @@ class ResPartner(models.Model): cooperator = fields.Boolean(string='Cooperator', help="Check this box if this contact is a" - " cooperator(effective or not).") + " cooperator (effective or not).") member = fields.Boolean(string='Effective cooperator', help="Check this box if this cooperator" " is an effective member.") @@ -98,6 +98,7 @@ class ResPartner(models.Model): old_member = fields.Boolean(string='Old cooperator', help="Check this box if this cooperator is" " no more an effective member.") + # todo use oca partner_contact_gender gender = fields.Selection([('male', 'Male'), ('female', 'Female'), ('other', 'Other')], From 5159337ffa1bc94bb2b6a6cf192c32fd2c432aab Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Wed, 9 Oct 2019 15:36:49 +0200 Subject: [PATCH 4/6] [IMP] emc test and demo data for basic flow --- easy_my_coop/__manifest__.py | 39 ++++---- easy_my_coop/demo/coop.xml | 122 +++++++++++++++++++++++ easy_my_coop/models/operation_request.py | 1 + easy_my_coop/tests/__init__.py | 1 + easy_my_coop/tests/test_coop.py | 70 +++++++++++++ 5 files changed, 215 insertions(+), 18 deletions(-) create mode 100644 easy_my_coop/demo/coop.xml create mode 100644 easy_my_coop/tests/__init__.py create mode 100644 easy_my_coop/tests/test_coop.py diff --git a/easy_my_coop/__manifest__.py b/easy_my_coop/__manifest__.py index 6964feb..aed426e 100644 --- a/easy_my_coop/__manifest__.py +++ b/easy_my_coop/__manifest__.py @@ -4,25 +4,25 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { - "name": "Easy My Coop", - "version": "12.0.2.0.2", - "depends": [ - "base", - "web", - "sale", - "account", - "base_iban", - "product", - "partner_firstname", - "partner_contact_birthdate", - "partner_contact_address", - "email_template_config", + 'name': 'Easy My Coop', + 'version': '12.0.2.0.2', + 'depends': [ + 'base', + 'web', + 'sale', + 'account', + 'base_iban', + 'product', + 'partner_firstname', + 'partner_contact_birthdate', + 'partner_contact_address', + 'email_template_config', ], - "author": "Coop IT Easy SCRLfs", - "category": "Cooperative management", - "website": "https://www.coopiteasy.be", - "license": "AGPL-3", - "description": """ + 'author': 'Coop IT Easy SCRLfs', + 'category': 'Cooperative management', + 'website': 'https://www.coopiteasy.be', + 'license': 'AGPL-3', + 'description': """ This module allows to manage the cooperator subscription and all the cooperative business processes. """, @@ -51,6 +51,9 @@ 'report/cooperator_register_G001.xml', 'data/mail_template_data.xml', # Must be loaded after reports ], + 'demo': [ + 'demo/coop.xml', + ], 'installable': True, 'application': True, } diff --git a/easy_my_coop/demo/coop.xml b/easy_my_coop/demo/coop.xml new file mode 100644 index 0000000..5897486 --- /dev/null +++ b/easy_my_coop/demo/coop.xml @@ -0,0 +1,122 @@ + + + + + + Virginie Leloup + + + virginie@demo.net + Avenue des Dessus-de-Livres, 2 + Namur (Loyers) + 5101 + + + + + Houssine Intégrale + + + houssine@demo.net + Avenue des Dessous-de-Livres, 3 + Namur (Loyers) + 5101 + + + + + Vincent Bixolon + + + vincent@demo.net + Rue de la colocation, 23 + Namur (Loyers) + 5101 + + + + + Rémy Commit + + + remy@demo.net + Rue Guido Van Rossum, 2 + Evere + 5101 + + + + + 416000 + Cooperators + + + + + + Part A - Founder + Part A + + + + 2 + + + 50 + + + + + + + + + Part B - Worker + Part B + + + + 2 + + + 25 + + + + + + + + + Manuel Dublues + manuel@demo.net + schaerbeekstraat + 1111 + Brussels + + + manual + 3 + + en_US + + + + + 2 + 50 + + + + + + + 4 + 50 + + + + diff --git a/easy_my_coop/models/operation_request.py b/easy_my_coop/models/operation_request.py index cadaffe..3972578 100644 --- a/easy_my_coop/models/operation_request.py +++ b/easy_my_coop/models/operation_request.py @@ -10,6 +10,7 @@ class operation_request(models.Model): _description = "Operation request" def get_date_now(self): + # fixme odoo 12 uses date types return datetime.strftime(datetime.now(), '%Y-%m-%d') @api.multi diff --git a/easy_my_coop/tests/__init__.py b/easy_my_coop/tests/__init__.py new file mode 100644 index 0000000..d83361d --- /dev/null +++ b/easy_my_coop/tests/__init__.py @@ -0,0 +1 @@ +from . import test_coop diff --git a/easy_my_coop/tests/test_coop.py b/easy_my_coop/tests/test_coop.py new file mode 100644 index 0000000..a312885 --- /dev/null +++ b/easy_my_coop/tests/test_coop.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +import odoo.tests.common as common +from odoo.fields import Date + + +class TestCoop(common.TransactionCase): + def setUp(self): + super(TestCoop, self).setUp() + + self.request = self.browse_ref( + "easy_my_coop.subscription_request_1_demo" + ) + self.bank_journal_euro = self.env["account.journal"].create( + {"name": "Bank", "type": "bank", "code": "BNK67"} + ) + self.payment_method_manual_in = self.env.ref( + "account.account_payment_method_manual_in" + ) + + def test_put_on_waiting_list(self): + self.request.put_on_waiting_list() + self.assertEquals(self.request.state, "waiting") + + def test_validate_subscription_request(self): + self.request.validate_subscription_request() + + self.assertEquals(self.request.state, "done") + self.assertTrue(self.request.partner_id) + self.assertTrue(self.request.partner_id.coop_candidate) + self.assertFalse(self.request.partner_id.member) + self.assertEquals(self.request.type, "new") + self.assertTrue(len(self.request.capital_release_request) >= 1) + self.assertEquals(self.request.capital_release_request.state, "open") + self.assertTrue(self.request.capital_release_request.sent) + + def test_register_payment_for_capital_release(self): + self.request.validate_subscription_request() + invoice = self.request.capital_release_request + + ctx = {"active_model": "account.invoice", "active_ids": [invoice.id]} + register_payments = ( + self.env["account.register.payments"] + .with_context(ctx) + .create( + { + "payment_date": Date.today(), + "journal_id": self.bank_journal_euro.id, + "payment_method_id": self.payment_method_manual_in.id, + } + ) + ) + register_payments.create_payments() + self.assertEquals(self.request.capital_release_request.state, "paid") + + partner = self.request.partner_id + self.assertFalse(partner.coop_candidate) + self.assertTrue(partner.member) + self.assertTrue(partner.share_ids) + self.assertEquals(self.request.partner_id.effective_date, Date.today()) + + share = partner.share_ids[0] + self.assertEquals(share.share_number, self.request.ordered_parts) + self.assertEquals( + share.share_product_id, self.request.share_product_id + ) + self.assertEquals(share.effective_date, Date.today()) From b694520b191f8fc26c419960e5c80fbf28a27dbf Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Wed, 9 Oct 2019 15:46:49 +0200 Subject: [PATCH 5/6] [ADD] emc: add licences --- easy_my_coop/models/account_invoice.py | 6 ++++++ easy_my_coop/models/account_journal.py | 6 ++++++ easy_my_coop/models/company.py | 6 ++++++ easy_my_coop/models/coop.py | 6 ++++++ easy_my_coop/models/operation_request.py | 5 +++++ easy_my_coop/models/partner.py | 6 ++++++ easy_my_coop/models/product.py | 6 ++++++ easy_my_coop/models/res_partner_bank.py | 6 ++++++ 8 files changed, 47 insertions(+) diff --git a/easy_my_coop/models/account_invoice.py b/easy_my_coop/models/account_invoice.py index 08c8dad..f3731fd 100644 --- a/easy_my_coop/models/account_invoice.py +++ b/easy_my_coop/models/account_invoice.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + from datetime import datetime from odoo import api, fields, models diff --git a/easy_my_coop/models/account_journal.py b/easy_my_coop/models/account_journal.py index 32c0104..9ec7ae1 100644 --- a/easy_my_coop/models/account_journal.py +++ b/easy_my_coop/models/account_journal.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + from odoo import fields, models diff --git a/easy_my_coop/models/company.py b/easy_my_coop/models/company.py index 81cc9fc..86572aa 100644 --- a/easy_my_coop/models/company.py +++ b/easy_my_coop/models/company.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + from odoo import api, fields, models diff --git a/easy_my_coop/models/coop.py b/easy_my_coop/models/coop.py index a88c472..1a13664 100644 --- a/easy_my_coop/models/coop.py +++ b/easy_my_coop/models/coop.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + from datetime import datetime from odoo import api, fields, models, _ diff --git a/easy_my_coop/models/operation_request.py b/easy_my_coop/models/operation_request.py index 3972578..f4b5ded 100644 --- a/easy_my_coop/models/operation_request.py +++ b/easy_my_coop/models/operation_request.py @@ -1,4 +1,9 @@ # -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + from datetime import datetime from odoo import api, fields, models, _ diff --git a/easy_my_coop/models/partner.py b/easy_my_coop/models/partner.py index ea61b35..0b40220 100644 --- a/easy_my_coop/models/partner.py +++ b/easy_my_coop/models/partner.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + from odoo import api, fields, models diff --git a/easy_my_coop/models/product.py b/easy_my_coop/models/product.py index 5ca3ed6..0706a1d 100644 --- a/easy_my_coop/models/product.py +++ b/easy_my_coop/models/product.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + from odoo import api, fields, models diff --git a/easy_my_coop/models/res_partner_bank.py b/easy_my_coop/models/res_partner_bank.py index 1a3aa98..53e2bb5 100644 --- a/easy_my_coop/models/res_partner_bank.py +++ b/easy_my_coop/models/res_partner_bank.py @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + from odoo import models From ef2d9f9700aa3a4b0a25d4191cb8dcbd2af85fc3 Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Wed, 9 Oct 2019 20:30:27 +0200 Subject: [PATCH 6/6] [FIX] emh: set representative parent_id to request subscriber --- easy_my_coop/models/coop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/easy_my_coop/models/coop.py b/easy_my_coop/models/coop.py index 1a13664..e3c8c36 100644 --- a/easy_my_coop/models/coop.py +++ b/easy_my_coop/models/coop.py @@ -492,7 +492,7 @@ class SubscriptionRequest(models.Model): 'out_inv_comm_algorithm': 'random', 'lang': self.lang, 'birthdate_date': self.birthdate, - 'parent_id': partner.id, + 'parent_id': self.partner.id, 'representative': True, 'function': self.contact_person_function, 'type': 'representative',