[REF]GOLEM Family Membership : small refactorings / quality

This commit is contained in:
Fabien BOURGEOIS 2018-08-20 11:33:26 +02:00
parent 3676634790
commit 390bcb18f1
4 changed files with 25 additions and 22 deletions

View File

@ -17,16 +17,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
{ {
'name': 'GOLEM families membership', 'name': 'GOLEM Family Memberships',
'summary': 'GOLEM Families membership ', 'summary': 'GOLEM Family Membership Management',
'description': 'GOLEM Families Membership', 'description': 'GOLEM Family Membership Management',
'version': '10.0.0.0.0', 'version': '10.0.0.1.0',
'category': 'GOLEM', 'category': 'GOLEM',
'author': 'Fabien Bourgeois, Youssef ELOUAHBY', 'author': 'Fabien Bourgeois, Youssef ELOUAHBY',
'license': 'AGPL-3', 'license': 'AGPL-3',
'application': False, 'application': False,
'installable': True, 'installable': True,
'depends': ['golem_family'], 'depends': ['golem_family', 'membership'],
'data': ['views/golem_family_views.xml', 'data': ['views/golem_family_views.xml',
'wizard/golem_membership_invoice_views.xml'] 'wizard/golem_membership_invoice_views.xml']
} }

View File

@ -18,7 +18,8 @@
""" GOLEM Families Adaptations""" """ GOLEM Families Adaptations"""
from odoo import models, fields, api, _ from odoo import models, api, _
class GolemFamily(models.Model): class GolemFamily(models.Model):
""" GOLEM Family Adaptations """ """ GOLEM Family Adaptations """
@ -28,12 +29,12 @@ class GolemFamily(models.Model):
def family_membership(self): def family_membership(self):
""" Wizard call for family membership """ """ Wizard call for family membership """
self.ensure_one() self.ensure_one()
family_id = self[0] family = self[0]
return { return {
'name' : _('Please fill the family membership form'), 'name' : _('Please fill the family membership form'),
'type' : 'ir.actions.act_window', 'type' : 'ir.actions.act_window',
'res_model' : 'golem.membership.invoice', 'res_model' : 'golem.membership.invoice',
'context': {'default_family_id': family_id.id}, 'context': {'default_family_id': family.id},
'view_mode': 'form', 'view_mode': 'form',
'target': 'new' 'target': 'new'
} }

View File

@ -24,27 +24,26 @@ class GolemMembershipInvoice(models.TransientModel):
""" GOLEM Membership Invoice adaptations """ """ GOLEM Membership Invoice adaptations """
_inherit = 'golem.membership.invoice' _inherit = 'golem.membership.invoice'
family_id = fields.Many2one('golem.family') family_id = fields.Many2one('golem.family', required=True)
members_ids = fields.Many2many('res.partner') members_ids = fields.Many2many('res.partner')
on_the_name_of = fields.Many2one('res.partner', domain="[('id', '=', members_ids[0][2])]") on_the_name_of = fields.Many2one('res.partner', domain="[('id', '=', members_ids[0][2])]")
@api.onchange('family_id') @api.onchange('family_id')
def onchange_family_id(self): def onchange_family(self):
""" fill members_ids """ """ Fill members_ids """
for record in self: for record in self:
for member in record.family_id.member_ids: record.members_ids = [(6, False, record.family_id.members_ids.ids)]
record.members_ids += member
@api.multi @api.multi
def membership_family_invoice(self): def membership_family_invoice(self):
""" Create family membership """ """ Create family membership """
self.ensure_one() self.ensure_one()
record = self[0] record = self[0]
datas = {'membership_product_id': self.product_id.id, datas = {'membership_product_id': record.product_id.id,
'amount': self.member_price} 'amount': record.member_price}
invoice_list = record.on_the_name_of.create_membership_invoice(datas=datas) invoice_list = record.on_the_name_of.create_membership_invoice(datas=datas)
datas = {'membership_product_id': self.product_id.id, datas = {'membership_product_id': record.product_id.id,
'amount': 0} 'amount': 0.0}
gen = (member for member in record.members_ids if member != record.on_the_name_of) gen = (member for member in record.members_ids if member != record.on_the_name_of)
for member in gen: for member in gen:
id_membership = member.create_membership_invoice(datas=datas) id_membership = member.create_membership_invoice(datas=datas)

View File

@ -16,17 +16,19 @@ GNU Affero General Public License for more details.
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/>.
--> -->
<odoo> <odoo>
<data> <data>
<!-- Forms --> <!-- Forms -->
<record id="golem_membership_family_invoice_form" model="ir.ui.view"> <record id="golem_membership_family_invoice_form" model="ir.ui.view">
<field name="name">membership.family.invoice.view.form</field> <field name="name">GOLEM Membership Family Invoice Form</field>
<field name="model">golem.membership.invoice</field> <field name="model">golem.membership.invoice</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Membership Invoice"> <form string="Membership Invoice">
<group> <group>
<field name="family_id" readonly="1"/> <field name="family_id" readonly="1" />
<field name="members_ids" invisible="1" widget="many2many_tags"/> <field name="members_ids" widget="many2many_tags" />
<field name="on_the_name_of" options="{'no_create': True}" /> <field name="on_the_name_of" options="{'no_create': True}" />
<field name="product_id" domain="[('membership','=',True)]" <field name="product_id" domain="[('membership','=',True)]"
widget="selection" /> widget="selection" />
@ -41,5 +43,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</form> </form>
</field> </field>
</record> </record>
</data> </data>
</odoo> </odoo>