Browse Source

[MERGE] 9.0-activate-deactivate-card-Elise : 0003 - Carte BEES - Code à barre

pull/7/head
Thibault Francois 9 years ago
parent
commit
9ef6cd06c2
  1. 1
      beesdoo_base/__init__.py
  2. 1
      beesdoo_base/__openerp__.py
  3. 2
      beesdoo_base/models/__init__.py
  4. 24
      beesdoo_base/models/membercard.py
  5. 29
      beesdoo_base/models/partner.py
  6. 24
      beesdoo_base/views/partner.xml
  7. 1
      beesdoo_base/wizard/__init__.py
  8. 22
      beesdoo_base/wizard/new_member_card.py
  9. 21
      beesdoo_base/wizard/views/new_member_card.xml
  10. 1
      beesdoo_project/models/task.py

1
beesdoo_base/__init__.py

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import models import models
import wizard
import tools import tools

1
beesdoo_base/__openerp__.py

@ -20,5 +20,6 @@
'data': [ 'data': [
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'views/partner.xml', 'views/partner.xml',
'wizard/views/new_member_card.xml',
], ],
} }

2
beesdoo_base/models/__init__.py

@ -1 +1 @@
import partner
import partner, membercard

24
beesdoo_base/models/membercard.py

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api
import uuid
class MemberCard(models.Model):
def _get_current_user(self):
return self.env.uid
def _compute_bar_code(self):
rule = self.env['barcode.rule'].search([('name', '=', 'Customer Barcodes')])[0]
size = 13 - len(rule.pattern)
ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size]
return ean[0:12] + str(self.env['barcode.nomenclature'].ean_checksum(ean))
_name = 'member.card'
_order = 'create_date desc'
valid = fields.Boolean(default=True, string="Active")
barcode = fields.Char("Barcode", oldname='ean13', default=_compute_bar_code)
partner_id = fields.Many2one('res.partner') #, default=_get_current_client)
responsible_id = fields.Many2one('res.users', default=_get_current_user, string="Responsible")
end_date = fields.Date(readonly=True, string="Expiration Date")
comment = fields.Char("Reason", required=True)

29
beesdoo_base/models/partner.py

@ -9,14 +9,10 @@ class Partner(models.Model):
first_name = fields.Char('First Name') first_name = fields.Char('First Name')
last_name = fields.Char('Last Name', required=True) last_name = fields.Char('Last Name', required=True)
eater = fields.Selection([('eater', 'Eater'), ('worker_eater', 'Worker and Eater')], string="Eater/Worker") 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), child_eater_ids = fields.One2many("res.partner", "parent_eater_id", domain=[('customer', '=', True),
('eater', '=', 'eater')]) ('eater', '=', 'eater')])
parent_eater_id = fields.Many2one("res.partner", string="Parent Worker", readonly=True) parent_eater_id = fields.Many2one("res.partner", string="Parent Worker", readonly=True)
barcode = fields.Char(compute="_get_bar_code", string='Bar Code', store=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) parent_barcode = fields.Char(compute="_get_bar_code", string='Parent Bar Code', store=True)
member_card_ids = fields.One2many('member.card', 'partner_id') member_card_ids = fields.One2many('member.card', 'partner_id')
@ -31,7 +27,9 @@ class Partner(models.Model):
if self.eater == 'eater': if self.eater == 'eater':
self.parent_barcode = self.parent_eater_id.barcode self.parent_barcode = self.parent_eater_id.barcode
elif self.member_card_ids: elif self.member_card_ids:
self.barcode = self.member_card_ids[0].barcode
for c in self.member_card_ids:
if c.valid:
self.barcode = c.barcode
@api.one @api.one
@api.constrains('child_eater_ids', 'parent_eater_id') @api.constrains('child_eater_ids', 'parent_eater_id')
@ -50,18 +48,13 @@ class Partner(models.Model):
command[0] = 3 command[0] = 3
return super(Partner, self).write(values) return super(Partner, self).write(values)
class MemberCard(models.Model):
def _get_current_user(self):
return self.env.user
@api.one
def _deactivate_active_cards(self):
for card in self.member_card_ids.filtered('valid'):
card.valid = False
card.end_date = fields.Date.today()
_name = 'member.card'
_order = 'activation_date desc'
@api.multi
def _new_card(self, reason, user_id):
self.env['member.card'].create({'partner_id' : self.id,'responsible_id' : user_id, 'comment' : reason})
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")

24
beesdoo_base/views/partner.xml

@ -1,18 +1,27 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<record model="ir.actions.act_window" id="action_membercard_wizard">
<field name="name">New Member Card</field>
<field name="res_model">membercard.new.wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record model="ir.ui.view" id="beesdoo_partner_form_view"> <record model="ir.ui.view" id="beesdoo_partner_form_view">
<field name="name">beesdoo.partner.form.view</field> <field name="name">beesdoo.partner.form.view</field>
<field name="model">res.partner</field> <field name="model">res.partner</field>
<field name="inherit_id" ref="point_of_sale.view_partner_property_form" /> <field name="inherit_id" ref="point_of_sale.view_partner_property_form" />
<field name="arch" type="xml" >
<field name="arch" type="xml">
<field name="name" position="replace"> <field name="name" position="replace">
<field name="name" class="oe_read_only" /> <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 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>
<field name="website" position="after"> <field name="website" position="after">
<field name="eater" attrs="{'invisible': [('company_type', '=', 'company')]}"/>
<field name="eater"
attrs="{'invisible': [('company_type', '=', 'company')]}" />
<field name="parent_eater_id" attrs="{'invisible' : [('eater', '!=', 'eater')]}" /> <field name="parent_eater_id" attrs="{'invisible' : [('eater', '!=', 'eater')]}" />
</field> </field>
<xpath expr="//notebook" position="inside"> <xpath expr="//notebook" position="inside">
@ -24,12 +33,17 @@
<field string="Cartes" name="member_card_ids"> <field string="Cartes" name="member_card_ids">
<tree editable="bottom"> <tree editable="bottom">
<field name="barcode" /> <field name="barcode" />
<field name="activation_date" />
<field name="create_date" />
<field name="end_date" /> <field name="end_date" />
<field name="responsible_id" /> <field name="responsible_id" />
<field name="comment" /> <field name="comment" />
<field name="valid" />
</tree> </tree>
</field> </field>
<group>
<button string="Nouvelle Carte" name="%(action_membercard_wizard)d"
type="action" />
</group>
</page> </page>
</xpath> </xpath>
<field name="barcode" position="attributes"> <field name="barcode" position="attributes">

1
beesdoo_base/wizard/__init__.py

@ -0,0 +1 @@
import new_member_card

22
beesdoo_base/wizard/new_member_card.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from openerp import models, fields, api
class NewMemberCardWizard(models.TransientModel):
"""
A transient model for the creation of a new card.
The user can only define the raison why a new card is
needed and the eater/worker that is concerned.
"""
_name = 'membercard.new.wizard'
def _get_default_partner(self):
return self.env.context['active_id']
new_comment = fields.Text('Reason', required=True)
partner_id = fields.Many2one('res.partner', default=_get_default_partner)
@api.one
def create_new_card(self):
client = self.partner_id.sudo()
client._deactivate_active_cards()
client._new_card(self.new_comment, self.env.uid)

21
beesdoo_base/wizard/views/new_member_card.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="MemberCard Wizard" model="ir.ui.view">
<field name="name">New MemberCard Wizard</field>
<field name="model">membercard.new.wizard</field>
<field name="arch" type="xml">
<form>
<separator string="Reason" />
<field name="new_comment" string="Raison" editable="True" />
<field name="partner_id" invisible="1" />
<footer>
<button type="object" name="create_new_card" string="Créer"
class="oe_highlight" />
<button special="cancel" string="Annuler" />
</footer>
</form>
</field>
</record>
</odoo>

1
beesdoo_project/models/task.py

@ -18,4 +18,3 @@ class Task(models.Model):
relation="link_task_relation_table", relation="link_task_relation_table",
column1='user1_id', column1='user1_id',
column2='user2_id', string="Linked Tasks") column2='user2_id', string="Linked Tasks")
Loading…
Cancel
Save