Browse Source

[MERGE][TASK 0010] Gestion de foyer de mangeurs

pull/6/head
Thibault Francois 9 years ago
parent
commit
3f4d9f69c7
  1. 8
      README.md
  2. 3
      beesdoo_base/__openerp__.py
  3. 55
      beesdoo_base/models/partner.py
  4. 2
      beesdoo_base/security/ir.model.access.csv
  5. 30
      beesdoo_base/views/partner.xml

8
README.md

@ -1 +1,9 @@
# Obeesdoo
# Migrate barcode
```sql
insert into member_card (active, barcode, partner_id, responsible_id, activation_date) select 't', barcode, id, 1, '2016-01-01' from res_partner where barcode is not null;
update res_partner set eater = 'worker_eater' where barcode is not null;
```

3
beesdoo_base/__openerp__.py

@ -15,9 +15,10 @@
'category': 'Project Management',
'version': '0.1',
'depends': ['base'],
'depends': ['point_of_sale'],
'data': [
'security/ir.model.access.csv',
'views/partner.xml',
],
}

55
beesdoo_base/models/partner.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api
from openerp import models, fields, api, _
from openerp.exceptions import ValidationError
from openerp.addons.beesdoo_base.tools import concat_names
class Partner(models.Model):
@ -9,6 +10,58 @@ class Partner(models.Model):
first_name = fields.Char('First Name')
last_name = fields.Char('Last Name', required=True)
eater = fields.Selection([('eater', 'Eater'), ('worker_eater', 'Worker and Eater')], string="Eater/Worker")
child_eater_ids = fields.One2many("res.partner", "parent_eater_id", domain=[('customer', '=', True),
('eater', '=', 'eater')])
parent_eater_id = fields.Many2one("res.partner", string="Parent Worker", readonly=True)
barcode = fields.Char(compute="_get_bar_code", string='Bar Code', store=True)
parent_barcode = fields.Char(compute="_get_bar_code", string='Parent Bar Code', store=True)
member_card_ids = fields.One2many('member.card', 'partner_id')
@api.onchange('first_name', 'last_name')
def _on_change_name(self):
self.name = concat_names(self.first_name, self.last_name)
@api.one
@api.depends('parent_eater_id', 'parent_eater_id.barcode', 'eater', 'member_card_ids')
def _get_bar_code(self):
if self.eater == 'eater':
self.parent_barcode = self.parent_eater_id.barcode
elif self.member_card_ids:
self.barcode = self.member_card_ids[0].barcode
@api.one
@api.constrains('child_eater_ids', 'parent_eater_id')
def _only_two_eaters(self):
if len(self.child_eater_ids) > 2 or len(self.parent_eater_id.child_eater_ids) > 2:
raise ValidationError(_('You can only set two additional eaters per worker'))
@api.multi
def write(self, values):
if values.get('parent_eater_id') and self.parent_eater_id:
raise ValidationError(_('You try to assign a eater to a worker but this easer is alread assign to %s please remove it before') % self.parent_eater_id.name)
#replace many2many command when writing on child_eater_ids to just remove the link
if 'child_eater_ids' in values:
for command in values['child_eater_ids']:
if command[0] == 2:
command[0] = 3
return super(Partner, self).write(values)
class MemberCard(models.Model):
def _get_current_user(self):
return self.env.user
_name = 'member.card'
_order = 'activation_date desc'
active = fields.Boolean(default=True)
barcode = fields.Char('Barcode', oldname='ean13')
partner_id = fields.Many2one('res.partner')
responsible_id = fields.Many2one('res.users', default=_get_current_user)
activation_date = fields.Date(default=fields.Date.today, readonly=True)
end_date = fields.Date()
comment = fields.Char("Reason")

2
beesdoo_base/security/ir.model.access.csv

@ -0,0 +1,2 @@
"id","name","model_id/id","group_id/id","perm_read","perm_write","perm_create","perm_unlink"
"member_card_read_all","member card read all","beesdoo_base.model_member_card","","True","False","False","False"

30
beesdoo_base/views/partner.xml

@ -1,15 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.ui.view" id="beesdoo_partner_form_view">
<field name="name">beesdoo.partner.form.view</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="inherit_id" ref="point_of_sale.view_partner_property_form" />
<field name="arch" type="xml" >
<field name="name" position="replace">
<field name="name" class="oe_read_only" />
<field name="first_name" placeholder="First Name" class="oe_edit_only" attrs="{'invisible' : [('company_type', '=', 'company')]}"/>
<field name="last_name" placeholder="Last Name" class="oe_edit_only" default_focus="1"/>
</field>
<field name="website" position="after">
<field name="eater" attrs="{'invisible': [('company_type', '=', 'company')]}"/>
<field name="parent_eater_id" attrs="{'invisible' : [('eater', '!=', 'eater')]}" />
</field>
<xpath expr="//notebook" position="inside">
<page string="Carte de Membre"
attrs="{'invisible': ['|', ('customer', '=', False), ('eater', '!=', 'worker_eater')]}">
<separator string="Mangeurs" />
<field name="child_eater_ids" widget="many2many_tags" />
<separator string="Cartes" />
<field string="Cartes" name="member_card_ids">
<tree editable="bottom">
<field name="barcode" />
<field name="activation_date" />
<field name="end_date" />
<field name="responsible_id" />
<field name="comment" />
</tree>
</field>
</page>
</xpath>
<field name="barcode" position="attributes">
<attribute name="attrs">{'invisible' : [('eater', '!=', 'worker_eater')]}</attribute>
</field>
<field name="barcode" position="after">
<field name="parent_barcode" attrs="{'invisible' : [('eater', '!=', 'eater')]}" />
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save