From c6839312505473d8a06f3e57b9f8b88edd331ad4 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Tue, 17 Jul 2018 10:11:10 +0200 Subject: [PATCH] [IMP]GOLEM Activity Registration State : rounded payments Round payments with ceil payments for first ones, balance for the last one (or unique). --- golem_activity_registration_state/__manifest__.py | 2 +- .../wizard/golem_activity_registration_invoicing.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/golem_activity_registration_state/__manifest__.py b/golem_activity_registration_state/__manifest__.py index 3562e4f..74b1a58 100644 --- a/golem_activity_registration_state/__manifest__.py +++ b/golem_activity_registration_state/__manifest__.py @@ -19,7 +19,7 @@ 'name': 'GOLEM Activity Session Member Registrations States', 'summary': 'GOLEM Activities Session Member Registration states', 'description': 'GOLEM Activities Session Member Registration states', - 'version': '10.0.1.0.2', + 'version': '10.0.1.1.0', 'category': 'GOLEM', 'author': 'Fabien Bourgeois', 'license': 'AGPL-3', diff --git a/golem_activity_registration_state/wizard/golem_activity_registration_invoicing.py b/golem_activity_registration_state/wizard/golem_activity_registration_invoicing.py index e9ca80a..9645a26 100644 --- a/golem_activity_registration_state/wizard/golem_activity_registration_invoicing.py +++ b/golem_activity_registration_state/wizard/golem_activity_registration_invoicing.py @@ -18,6 +18,7 @@ """ GOLEM Activity Registration Invoicing Wizard """ import logging +from math import ceil from odoo import models, fields, api _LOGGER = logging.getLogger(__name__) @@ -81,18 +82,21 @@ class GolemActivityRegistrationInvoicing(models.TransientModel): """ Create payment if schedule has been chosen """ self.ensure_one() if self.schedule_id and self.schedule_id.occurences > 0: - # TODO: make more intelligent price cut amount = invoice.amount_total - amount_per_occurence = amount / self.schedule_id.occurences - for day in self.schedule_id.day_ids: + amount_per_occurence = ceil(amount / self.schedule_id.occurences) + for index, day in enumerate(self.schedule_id.day_ids): + payment_amount = (amount_per_occurence if index != + (len(self.schedule_id.day_ids.ids) - 1) + else amount) payment = self.env['account.payment'].new({ 'payment_type': 'inbound', 'partner_type': 'customer', 'partner_id': self.member_id.partner_id.id, - 'amount': amount_per_occurence, + 'amount': payment_amount, 'payment_date': day.day, 'journal_id': self.journal_id.id, }) + amount -= amount_per_occurence payment._onchange_journal() payment_values = dict(payment._cache) payment = self.env['account.payment'].create(payment_values)