Browse Source

[IMP] add a wizard to update readonly fields

pull/1/head
houssine 7 years ago
parent
commit
e8cdcff7d0
  1. 1
      easy_my_coop/__openerp__.py
  2. 4
      easy_my_coop/view/res_partner_view.xml
  3. 3
      easy_my_coop/wizard/__init__.py
  4. 2
      easy_my_coop/wizard/create_subscription_from_partner.py
  5. 47
      easy_my_coop/wizard/update_partner_info.py
  6. 35
      easy_my_coop/wizard/update_partner_info.xml

1
easy_my_coop/__openerp__.py

@ -43,6 +43,7 @@
'security/easy_my_coop_security.xml',
'security/ir.model.access.csv',
'wizard/create_subscription_from_partner.xml',
'wizard/update_partner_info.xml',
'view/subscription_request_view.xml',
'view/email_template_view.xml',
'view/res_partner_view.xml',

4
easy_my_coop/view/res_partner_view.xml

@ -9,7 +9,9 @@
<sheet position="before">
<header>
<button string="Create Subscription" name="%(action_view_create_subscription)d"
type="action" context="{'default_active_id': active_id}" class="oe_highlight" groups="easy_my_coop.group_energiris_manager"/>
type="action" context="{'default_active_id': active_id}" groups="easy_my_coop.group_energiris_manager"/>
<button string="Update info" name="%(action_view_update_partner_info)d"
type="action" context="{'default_active_id': active_id}" groups="easy_my_coop.group_energiris_manager"/>
</header>
</sheet>

3
easy_my_coop/wizard/__init__.py

@ -1,2 +1,3 @@
# -*- coding: utf-8 -*-
import create_subscription_from_partner
from . import create_subscription_from_partner
from . import update_partner_info

2
easy_my_coop/wizard/create_subscription_from_partner.py

@ -1,4 +1,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
# -*- coding: utf-8 -*-
import time

47
easy_my_coop/wizard/update_partner_info.py

@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
from openerp import api, fields, models, _
from openerp.exceptions import UserError
class PartnerUpdateInfo(models.TransientModel):
_name = "partner.update.info"
_description = "Update Partner Info"
@api.model
def _get_partner(self):
active_id = self.env.context.get('active_id')
return self.env['res.partner'].browse(active_id)
@api.model
def _get_register_number(self):
partner = self._get_partner()
if partner.is_company:
return partner.company_register_number
else:
return partner.national_register_number
register_number = fields.Char(string="Register Number", required=True, default=_get_register_number)
cooperator = fields.Many2one('res.partner', string="Cooperator", default=_get_partner)
def check_belgian_ident_id(self, register_number):
if self.env['subscription.request'].check_belgian_identification_id(register_number):
return True
else:
raise UserError(_("The national register number is not valid."))
@api.multi
def update(self):
cooperator = self.cooperator
coop_vals = {}
if self.is_company:
coop_vals['company_register_number'] = self.register_number
else:
if self.check_belgian_ident_id(self.register_number):
coop_vals['national_register_number'] = self.register_number
if coop_vals:
cooperator.write(coop_vals)
return True

35
easy_my_coop/wizard/update_partner_info.xml

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_update_partner_info" model="ir.ui.view">
<field name="name">Update Cooperator Info</field>
<field name="model">partner.update.info</field>
<field name="arch" type="xml">
<form string="Update Cooperator Info">
<p class="oe_grey">
Update Cooperator Info.
</p>
<group>
<field name="cooperator" readonly="True"/>
<field name="register_number"/>
</group>
<footer>
<button name="update" string="Update Info" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-default" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_view_update_partner_info" model="ir.actions.act_window">
<field name="name">Update Cooperator Info</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">partner.update.info</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="groups_id" eval="[(4,ref('easy_my_coop.group_energiris_manager'))]"/>
</record>
</data>
</openerp>
Loading…
Cancel
Save