diff --git a/sponsorship_compassion/README.rst b/sponsorship_compassion/README.rst index 4d6cf1824..c293044b7 100644 --- a/sponsorship_compassion/README.rst +++ b/sponsorship_compassion/README.rst @@ -17,7 +17,7 @@ Compassion Sponsorships :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-CompassionCH%2Fcompassion--modules-lightgray.png?logo=github - :target: https://github.com/CompassionCH/compassion-modules/tree/14.0/sponsorship_compassion + :target: https://github.com/CompassionCH/compassion-modules/tree/17.0/sponsorship_compassion :alt: CompassionCH/compassion-modules |badge1| |badge2| |badge3| @@ -62,7 +62,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -84,6 +84,6 @@ Contributors Maintainers ----------- -This module is part of the `CompassionCH/compassion-modules `_ project on GitHub. +This module is part of the `CompassionCH/compassion-modules `_ project on GitHub. You are welcome to contribute. diff --git a/sponsorship_compassion/__init__.py b/sponsorship_compassion/__init__.py index bc6bb3e70..cd6c48984 100644 --- a/sponsorship_compassion/__init__.py +++ b/sponsorship_compassion/__init__.py @@ -13,7 +13,7 @@ from . import models, wizards -def load_mappings(cr, registry): +def load_mappings(env): path = "sponsorship_compassion/static/mappings/" files = [ "anonymize_partner.json", @@ -21,4 +21,4 @@ def load_mappings(cr, registry): "create_sponsorship.json", "upsert_partner.json", ] - load_mapping_files(cr, path, files) + load_mapping_files(env, path, files) diff --git a/sponsorship_compassion/__manifest__.py b/sponsorship_compassion/__manifest__.py index 52502876b..790cbdb7b 100644 --- a/sponsorship_compassion/__manifest__.py +++ b/sponsorship_compassion/__manifest__.py @@ -29,7 +29,7 @@ # pylint: disable=C8101 { "name": "Compassion Sponsorships", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "category": "Compassion", "author": "Compassion CH", "license": "AGPL-3", @@ -41,9 +41,7 @@ "child_compassion", "partner_personal_info", "web_m2x_options", # oca/web - "web_notify", # oca/web "partner_firstname", # oca/partner-contact - "account_analytic_attribution", # compassion-accounting "sale", ], "data": [ @@ -76,9 +74,7 @@ "views/product_views.xml", "views/res_config_settings_view.xml", ], - "demo": [ - "demo/demo_data.xml", - ], + "demo": ["demo/product_product.xml"], "installable": True, "auto_install": False, "development_status": "Production/Stable", diff --git a/sponsorship_compassion/demo/demo_data.xml b/sponsorship_compassion/demo/demo_data.xml deleted file mode 100644 index 7d899dc76..000000000 --- a/sponsorship_compassion/demo/demo_data.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - Bilan : Debiteurs - receivable - income - - - 1050 - Receivables - - - - diff --git a/sponsorship_compassion/demo/product_product.xml b/sponsorship_compassion/demo/product_product.xml new file mode 100644 index 000000000..bc261a97c --- /dev/null +++ b/sponsorship_compassion/demo/product_product.xml @@ -0,0 +1,16 @@ + + + Sponsorship + + sponsorship + 42 + + + + General FUND + + fund_gen + 8 + + + diff --git a/sponsorship_compassion/models/child_compassion.py b/sponsorship_compassion/models/child_compassion.py index 1266bd0bb..68530e542 100644 --- a/sponsorship_compassion/models/child_compassion.py +++ b/sponsorship_compassion/models/child_compassion.py @@ -22,7 +22,6 @@ class ChildCompassion(models.Model): "recurring.contract", compute="_compute_related_contracts", string="Sponsorships", - readonly=True, ) has_been_sponsored = fields.Boolean(compute="_compute_has_been_sponsored") diff --git a/sponsorship_compassion/models/contract_group.py b/sponsorship_compassion/models/contract_group.py index e7575be2d..cfb2cbf97 100644 --- a/sponsorship_compassion/models/contract_group.py +++ b/sponsorship_compassion/models/contract_group.py @@ -22,9 +22,6 @@ class ContractGroup(models.Model): contains_sponsorship = fields.Boolean( string="Contains sponsorship", compute="_compute_contains_sponsorship", - readonly=True, - default=lambda s: s.env.context.get("default_type", None) - and "S" in s.env.context.get("default_type", "O"), ) ########################################################################## @@ -49,21 +46,6 @@ def _generate_invoices(self, invoicer, contract_id=None): contracts._generate_gifts(invoicer, CHRISTMAS_GIFT) return True - def build_inv_line_data( - self, invoicing_date=False, gift_wizard=False, contract_line=False - ): - # Push analytic account - res = super().build_inv_line_data(invoicing_date, gift_wizard, contract_line) - if gift_wizard: - res[ - "analytic_account_id" - ] = gift_wizard.contract_id.origin_id.analytic_id.id - elif contract_line: - res[ - "analytic_account_id" - ] = contract_line.contract_id.origin_id.analytic_id.id - return res - def _get_partner_for_contract(self, contract, gift_wizard=False): if gift_wizard and contract.send_gifts_to: return contract[contract.send_gifts_to] diff --git a/sponsorship_compassion/models/contract_origin.py b/sponsorship_compassion/models/contract_origin.py index 6ea955c3d..3cceca97e 100644 --- a/sponsorship_compassion/models/contract_origin.py +++ b/sponsorship_compassion/models/contract_origin.py @@ -40,14 +40,14 @@ class ContractOrigin(models.Model): required=True, index=True, ) - partner_id = fields.Many2one("res.partner", "Partner", readonly=False) - analytic_id = fields.Many2one( - "account.analytic.account", "Analytic Account", readonly=False - ) + partner_id = fields.Many2one("res.partner", "Partner") + analytic_id = fields.Many2one("account.analytic.account", "Analytic Account") contract_ids = fields.One2many( - "recurring.contract", "origin_id", "Sponsorships originated", readonly=True + "recurring.contract", + "origin_id", + "Sponsorships originated", ) - country_id = fields.Many2one("res.country", "Country", readonly=False) + country_id = fields.Many2one("res.country", "Country") other_name = fields.Char("Give details", size=128) won_sponsorships = fields.Integer(compute="_compute_won_sponsorships", store=True) conversion_rate = fields.Float(compute="_compute_won_sponsorships", store=True) diff --git a/sponsorship_compassion/models/contracts.py b/sponsorship_compassion/models/contracts.py index 02e7e5021..dfc84f597 100644 --- a/sponsorship_compassion/models/contracts.py +++ b/sponsorship_compassion/models/contracts.py @@ -47,7 +47,6 @@ class SponsorshipContract(models.Model): string="Correspondent", tracking=True, index=True, - readonly=False, ) partner_codega = fields.Char( "Partner ref", related="correspondent_id.ref", readonly=True @@ -70,14 +69,9 @@ class SponsorshipContract(models.Model): "res.lang.compassion", "Preferred language", tracking=True, - readonly=False, - ) - transfer_partner_id = fields.Many2one( - "compassion.global.partner", "Transferred to", readonly=False - ) - gmc_commitment_id = fields.Char( - help="Connect global ID", readonly=True, copy=False, tracking=True ) + transfer_partner_id = fields.Many2one("compassion.global.partner", "Transferred to") + gmc_commitment_id = fields.Char(help="Connect global ID", copy=False, tracking=True) hold_expiration_date = fields.Datetime( help="Used for setting a hold after sponsorship cancellation" ) @@ -96,13 +90,7 @@ class SponsorshipContract(models.Model): child_id = fields.Many2one( "compassion.child", "Sponsored child", - readonly=True, copy=False, - states={ - "draft": [("readonly", False)], - "waiting": [("readonly", False)], - "mandate": [("readonly", False)], - }, ondelete="restrict", tracking=True, index=True, @@ -131,7 +119,6 @@ class SponsorshipContract(models.Model): ondelete="restrict", tracking=True, index=True, - readonly=False, ) parent_id = fields.Many2one( "recurring.contract", @@ -139,10 +126,9 @@ class SponsorshipContract(models.Model): tracking=True, index=True, copy=False, - readonly=False, ) sub_sponsorship_id = fields.Many2one( - "recurring.contract", "sub sponsorship", readonly=True, copy=False, index=True + "recurring.contract", "sub sponsorship", copy=False, index=True ) partner_lang = fields.Selection( string="Partner language", related="partner_id.lang", store=True @@ -151,16 +137,14 @@ class SponsorshipContract(models.Model): "res.partner", "Partner", required=True, - readonly=False, - states={"terminated": [("readonly", True)]}, ondelete="restrict", tracking=True, ) gmc_payer_partner_id = fields.Many2one( - "res.partner", readonly=True, help="Partner synchronized with GMC as a payer." + "res.partner", help="Partner synchronized with GMC as a payer." ) gmc_correspondent_commitment_id = fields.Char( - readonly=True, help="Id of the correspondent commitment.", tracking=True + help="Id of the correspondent commitment.", tracking=True ) type = fields.Selection( [ @@ -175,7 +159,8 @@ class SponsorshipContract(models.Model): string="Sponsorship type", ) group_freq = fields.Char( - string="Payment frequency", compute="_compute_frequency", readonly=True + string="Payment frequency", + compute="_compute_frequency", ) is_first_sponsorship = fields.Boolean( compute="_compute_is_first_sponsorship", store=True @@ -264,23 +249,22 @@ def _get_sponsorship_standard_lines(self, correspondence): "default_code 'fund_gen' first." ) ) - sponsorship_product = sponsorship_product.product_variant_id gen_product = gen_product.product_variant_id - if self.company_id: - pricelist = self.pricelist_id - sponsorship_product.with_context( - {"pricelist": pricelist.id, "partner": self.partner_id.id} - )._compute_product_price() - gen_product.with_context( - {"pricelist": pricelist.id, "partner": self.partner_id.id} - )._compute_product_price() - + pricelist = self.pricelist_id + sponsorship_price = pricelist._get_product_price( + sponsorship_product, + 1.0, + ) + gen_price = pricelist._get_product_price( + gen_product, + 1.0, + ) sponsorship_vals = { "product_id": sponsorship_product.id, "quantity": 0 if correspondence else 1, - "amount": 0 if correspondence else sponsorship_product.list_price, - "subtotal": 0 if correspondence else sponsorship_product.list_price, + "amount": 0 if correspondence else sponsorship_price, + "subtotal": 0 if correspondence else sponsorship_price, } res.append((0, 0, sponsorship_vals)) # Avoid appending the GEN fund when one line already exists @@ -289,8 +273,8 @@ def _get_sponsorship_standard_lines(self, correspondence): gen_vals = { "product_id": gen_product.id, "quantity": 0 if correspondence else 1, - "amount": 0 if correspondence else gen_product.list_price, - "subtotal": 0 if correspondence else gen_product.list_price, + "amount": 0 if correspondence else gen_price, + "subtotal": 0 if correspondence else gen_price, } res.append((0, 0, gen_vals)) return res @@ -364,9 +348,9 @@ def _compute_contract_products(self): ) @api.depends("partner_id", "partner_id.ref", "child_id", "child_id.local_id") - def name_get(self): + def _compute_display_name(self): """Gives a friendly name for a sponsorship""" - result = [] + super()._compute_display_name() for contract in self: if contract.partner_id.ref or contract.reference: name = contract.partner_id.ref or contract.reference @@ -374,8 +358,9 @@ def name_get(self): name += " - " + contract.child_code elif contract.contract_line_ids: name += " - " + contract.contract_line_ids[0].product_id.name - result.append((contract.id, name)) - return result + contract.display_name = name + else: + contract.display_name = "Contract" @api.depends("activation_date", "state") def _compute_active(self): @@ -614,7 +599,7 @@ def write(self, vals): child.child_sponsored(vals["correspondent_id"]) if "reading_language" in vals: - (self - updated_correspondents)._on_language_changed() + (self - updated_correspondents).upsert_sponsorship() if old_partners: self.mapped("partner_id").update_number_sponsorships() @@ -843,7 +828,7 @@ def _contract_terminated(self, vals): def contract_waiting(self): contracts = self.filtered(lambda c: c.type == "O") - super(SponsorshipContract, self).contract_waiting() + super().contract_waiting() for contract in self - contracts: if not contract.start_date: contract.start_date = fields.Datetime.now() @@ -903,26 +888,6 @@ def upsert_sponsorship(self): ) return messages - ########################################################################## - # PRIVATE METHODS # - ########################################################################## - def _on_language_changed(self): - """Update the preferred language in GMC.""" - messages = self.upsert_sponsorship().with_context({"async_mode": False}) - error_msg = ( - "Error when updating sponsorship language. " - "You may be out of sync with GMC - please try again." - ) - for message in messages: - try: - message.process_messages() - if "failure" in message.state: - failure = message.failure_reason or error_msg - self.env.user.notify_danger(failure, "Language update failed.") - except Exception: - self.env.user.notify_danger(error_msg, "Language update failed.") - logger.error(error_msg, exc_info=True) - def _change_correspondent(self): self.ensure_one() if not self.correspondent_id.global_id: @@ -1312,9 +1277,9 @@ def migrate_gmc_correspondence_commitment(self): ) answer = onramp.send_message(f"beneficiaries/{global_id}/summary", "GET") commitments = ( - answer.get("content").get("Commitments") + answer.get("content", {}).get("Commitments", []) if answer.get("code") == 200 - else False + else [] ) if commitments: for commitment in commitments: diff --git a/sponsorship_compassion/models/recurring_contract_line.py b/sponsorship_compassion/models/recurring_contract_line.py index 73ef2a137..61a4aa1cd 100644 --- a/sponsorship_compassion/models/recurring_contract_line.py +++ b/sponsorship_compassion/models/recurring_contract_line.py @@ -24,7 +24,9 @@ class SponsorshipLine(models.Model): readonly=True, ) sponsorship_id = fields.Many2one( - "recurring.contract", "Sponsorship", ondelete="cascade", readonly=False + "recurring.contract", + "Sponsorship", + ondelete="cascade", ) @api.model diff --git a/sponsorship_compassion/models/res_partner.py b/sponsorship_compassion/models/res_partner.py index 3608b1e16..f61b48e81 100644 --- a/sponsorship_compassion/models/res_partner.py +++ b/sponsorship_compassion/models/res_partner.py @@ -36,7 +36,7 @@ class ResPartner(models.Model): default="correspondent", required=True, ) - global_id = fields.Char(copy=False, readonly=True) + global_id = fields.Char(copy=False) contracts_fully_managed = fields.One2many( "recurring.contract", compute="_compute_related_contracts", @@ -88,7 +88,9 @@ class ResPartner(models.Model): ) church_member_count = fields.Integer(compute="_compute_is_church", store=True) church_id = fields.Many2one( - "res.partner", "Church", domain=[("is_church", "=", True)], readonly=False + "res.partner", + "Church", + domain=[("is_church", "=", True)], ) gmc_gender = fields.Char(compute="_compute_gmc_gender") diff --git a/sponsorship_compassion/security/ir.model.access.csv b/sponsorship_compassion/security/ir.model.access.csv index 23006935a..8b808ce98 100644 --- a/sponsorship_compassion/security/ir.model.access.csv +++ b/sponsorship_compassion/security/ir.model.access.csv @@ -7,7 +7,6 @@ access_recurring_invoicer,Full access on recurring.invoicer,recurring_contract.m access_account_move,Full access on account.move,account.model_account_move,child_compassion.group_sponsorship,1,1,1,1 access_account_move_line,Full access on account.move.line,account.model_account_move_line,child_compassion.group_sponsorship,1,1,1,1 access_account_journal,Read access on account.journal,account.model_account_journal,child_compassion.group_sponsorship,1,0,0,0 -access_account_account_type,Read access on account.account.type,account.model_account_account_type,child_compassion.group_sponsorship,1,0,0,0 full_access_end_reason,Full access on recurring.contract.end.reason for SDS,recurring_contract.model_recurring_contract_end_reason,child_compassion.group_manager,1,1,1,1 access_generate_gift_wizard,access_generate_gift_wizard,model_generate_gift_wizard,account.group_account_manager,1,1,1,1,1,1,1,1 access_child_pictures_download_wizard,access_child_pictures_download_wizard,model_child_pictures_download_wizard,child_compassion.group_sponsorship,1,1,1,1 diff --git a/sponsorship_compassion/static/description/index.html b/sponsorship_compassion/static/description/index.html index 2700660f3..68e1268c2 100644 --- a/sponsorship_compassion/static/description/index.html +++ b/sponsorship_compassion/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -368,7 +369,7 @@

Compassion Sponsorships

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:97f9a5ee0b2a8f2eaa457ae9279964d7a48653250c7974abbfcdface332171a8 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Production/Stable License: AGPL-3 CompassionCH/compassion-modules

+

Production/Stable License: AGPL-3 CompassionCH/compassion-modules

Sponsorship management module. This module makes the link between child and contracts. It also customize contracts to fit the child sponsorship context.

@@ -417,7 +418,7 @@

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -feedback.

+feedback.

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

@@ -438,7 +439,7 @@

Contributors

Maintainers

-

This module is part of the CompassionCH/compassion-modules project on GitHub.

+

This module is part of the CompassionCH/compassion-modules project on GitHub.

You are welcome to contribute.

diff --git a/sponsorship_compassion/views/activate_contract_view.xml b/sponsorship_compassion/views/activate_contract_view.xml index d962f1b52..bc05bdd44 100644 --- a/sponsorship_compassion/views/activate_contract_view.xml +++ b/sponsorship_compassion/views/activate_contract_view.xml @@ -5,7 +5,7 @@ recurring.contract.activate.wizard -
+

This will mark the contract as Active, even if the partner has made no payment. Please be sure that you want to do this.