[ADD][WIP]Registration state : wizrd to create invoice and payments, according to selected schedule

This commit is contained in:
Fabien Bourgeois 2017-06-14 23:50:35 +02:00
parent b51dbb2df7
commit 8a1f8dcc48
7 changed files with 162 additions and 25 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com> # Copyright 2017 Fabien Bourgeois <fabien@yaltik.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -15,4 +15,4 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import models from . import models, wizard

View File

@ -24,7 +24,8 @@
'license': 'AGPL-3', 'license': 'AGPL-3',
'application': False, 'application': False,
'installable': True, 'installable': True,
'depends': ['golem_activity_registration'], 'depends': ['golem_activity_registration', 'golem_payment'],
'data': ['views/golem_activity_registration_views.xml', 'data': ['views/golem_activity_registration_views.xml',
'views/golem_member_views.xml', 'views/golem_activity_views.xml'] 'views/golem_member_views.xml', 'views/golem_activity_views.xml',
'wizard/golem_activity_registration_invoicing.xml']
} }

View File

@ -17,7 +17,7 @@
""" GOLEM Activity Registration State """ """ GOLEM Activity Registration State """
from odoo import models, fields, api from odoo import models, fields, api, _
class GolemMember(models.Model): class GolemMember(models.Model):
""" GOLEM Member adaptations """ """ GOLEM Member adaptations """
@ -40,10 +40,26 @@ class GolemMember(models.Model):
@api.multi @api.multi
def do_validate_registrations(self): def do_validate_registrations(self):
""" Validate all draft registrations """ """ Validate all draft registrations """
for member in self: self.ensure_one()
member = self[0]
draft_registrations = member.activity_registration_ids.filtered( draft_registrations = member.activity_registration_ids.filtered(
lambda r: r.state == 'draft') lambda r: r.state == 'draft')
draft_registrations.write({'state': 'confirmed'}) if draft_registrations:
invoicing = self.env['golem.activity.registration.invoicing'].create({
'member_id' : member.id,
'season_id': draft_registrations[0].activity_id.season_id.id
})
line_obj = self.env['golem.activity.registration.invoicing.line']
for reg in draft_registrations:
line_obj.create({'invoicing_id': invoicing.id,
'activity_id': reg.activity_id.id,
'price': reg.activity_id.list_price})
return {'name': _('Registration invoicing'),
'type': 'ir.actions.act_window',
'res_model': 'golem.activity.registration.invoicing',
'view_mode': 'form',
'res_id': invoicing.id,
'target': 'new'}
@api.multi @api.multi
def write(self, values): def write(self, values):

View File

@ -25,11 +25,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="inherit_id" <field name="inherit_id"
ref="golem_activity_registration.golem_member_form_inherit_golem_activity_registration" /> ref="golem_activity_registration.golem_member_form_inherit_golem_activity_registration" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<p name="default_season_label" position="after"> <field name="id" position="after">
<p attrs="{'invisible': [('id', '!=', False)]}" style="color:red;}"> <p attrs="{'invisible': [('id', '!=', False)]}" style="color:red;}"
colspan="2">
Note that you can't register activities if the member is new and not yet saved into the database. Note that you can't register activities if the member is new and not yet saved into the database.
</p> </p>
<p> <p colspan="2">
<field name="has_draft_registrations" invisible="1" /> <field name="has_draft_registrations" invisible="1" />
<button name="do_validate_registrations" type="object" <button name="do_validate_registrations" type="object"
string="Validate all draft registrations" string="Validate all draft registrations"
@ -37,7 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
help="If you validate draft registration, they will be seen as confirmed. Then, an invoice will be created for the current member." help="If you validate draft registration, they will be seen as confirmed. Then, an invoice will be created for the current member."
attrs="{'invisible': [('has_draft_registrations', '=', False)]}" /> attrs="{'invisible': [('has_draft_registrations', '=', False)]}" />
</p> </p>
</p> </field>
<!-- TODO : one by one cancelation --> <!-- TODO : one by one cancelation -->
<!-- TODO : do not allow removal if confirmed --> <!-- TODO : do not allow removal if confirmed -->
<tree position="attributes"> <tree position="attributes">
@ -46,9 +47,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<tree position="inside"> <tree position="inside">
<field name="state" invisible="1" /> <field name="state" invisible="1" />
</tree> </tree>
<field name="member_id" position="after">
<field name="invoice_id" readonly="1" />
</field>
</field> </field>
</record> </record>

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Fabien Bourgeois <fabien@yaltik.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import golem_activity_registration_invoicing

View File

@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# copyright 2017 fabien bourgeois <fabien@yaltik.com>
#
# this program is free software: you can redistribute it and/or modify
# it under the terms of the gnu affero general public license as
# published by the free software foundation, either version 3 of the
# license, or (at your option) any later version.
#
# this program is distributed in the hope that it will be useful,
# but without any warranty; without even the implied warranty of
# merchantability or fitness for a particular purpose. see the
# gnu affero general public license for more details.
#
# you should have received a copy of the gnu affero general public license
# along with this program. if not, see <http://www.gnu.org/licenses/>.
""" GOLEM Activity Registration Invoicing Wizard """
from odoo import models, fields, api
class GolemActivityRegistrationInvoicingLine(models.TransientModel):
""" GOLEM Activity Registration Invoicing Lines """
_name = 'golem.activity.registration.invoicing.line'
description = 'GOLEM Activity Registration Invoicing Lines'
invoicing_id = fields.Many2one('golem.activity.registration.invoicing',
required=True)
activity_id = fields.Many2one('golem.activity', required=True, readonly=True)
price = fields.Float('Price')
class GolemActivityRegistrationInvoicing(models.TransientModel):
""" GOLEM Activity Registration Invoicing Wizard """
_name = 'golem.activity.registration.invoicing'
_description = 'GOLEM Activity Registration Invoicing Wizard'
season_id = fields.Many2one('golem.season', 'Season', required=True)
member_id = fields.Many2one('golem.member', 'Member', required=True)
line_ids = fields.One2many('golem.activity.registration.invoicing.line',
'invoicing_id', string='Activities')
schedule_id = fields.Many2one('golem.payment.schedule', 'Payment schedule',
domain='[("season_id", "=", season_id)]',
help='If no schedule is selected, only the '
'invoice will be create. Otherwise, draft '
'payments will be generated.')
@api.multi
def validate(self):
""" Validate and create invoice and payments """
self.ensure_one()
draft_registrations = self.member_id.activity_registration_ids.filtered(
lambda r: r.state == 'draft')
draft_registrations.write({'state': 'confirmed'})

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2017 Fabien Bourgeois <fabien@yaltik.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!-- Form -->
<record id="invoicing_form" model="ir.ui.view">
<field name="name">GOLEM Activity Registration Invoicing Form</field>
<field name="model">golem.activity.registration.invoicing</field>
<field name="arch" type="xml">
<form string="Registration invoicing">
<p class="oe_grey">Please confirm activity prices and choose a payment schedule if needed.</p>
<group>
<field name="season_id" readonly="1" />
<field name="member_id" readonly="1" />
<field name="line_ids" string="Activities and Prices">
<tree delete="false" create="false" edit="true" editable="bottom">
<field name="activity_id" readonly="1" />
<field name="price" sum="Total" />
</tree>
</field>
<field name="schedule_id" />
</group>
<footer>
<button name="validate" string="Validate" type="object"
class="oe_highlight" />
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</data>
</odoo>