Browse Source
[IMP] add wizard to create a subscription request right from the res
[IMP] add wizard to create a subscription request right from the res
partnerpull/1/head
houssine
7 years ago
7 changed files with 152 additions and 2 deletions
-
1easy_my_coop/__init__.py
-
1easy_my_coop/__openerp__.py
-
2easy_my_coop/models/coop.py
-
7easy_my_coop/view/res_partner_view.xml
-
2easy_my_coop/wizard/__init__.py
-
99easy_my_coop/wizard/create_subscription_from_partner.py
-
40easy_my_coop/wizard/create_subscription_from_partner.xml
@ -1,3 +1,4 @@ |
|||||
from . import models |
from . import models |
||||
from . import controllers |
from . import controllers |
||||
from . import report |
from . import report |
||||
|
from . import wizard |
@ -1,2 +1,2 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
import cooperative_history_wizard |
|
||||
|
import create_subscription_from_partner |
@ -0,0 +1,99 @@ |
|||||
|
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
||||
|
|
||||
|
import time |
||||
|
|
||||
|
from openerp import api, fields, models, _ |
||||
|
import openerp.addons.decimal_precision as dp |
||||
|
from openerp.exceptions import UserError |
||||
|
|
||||
|
class PartnerCreateSubscription(models.TransientModel): |
||||
|
_name = "partner.create.subscription" |
||||
|
_description = "Create Subscription From Partner" |
||||
|
|
||||
|
@api.multi |
||||
|
@api.onchange('share_product') |
||||
|
def on_change_share_type(self): |
||||
|
self.share_qty = self.share_product.minimum_quantity |
||||
|
|
||||
|
@api.model |
||||
|
def _default_product_id(self): |
||||
|
domain = [('is_share','=',True),('default_share_product','=',True)] |
||||
|
active_id = self.env.context.get('active_id') |
||||
|
if active_id: |
||||
|
partner = self.env['res.partner'].browse(active_id) |
||||
|
if partner.is_company: |
||||
|
domain.append(('by_company','=',True)) |
||||
|
else: |
||||
|
domain.append(('by_individual','=',True)) |
||||
|
|
||||
|
return self.env['product.product'].search(domain) |
||||
|
|
||||
|
@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_is_company(self): |
||||
|
return self._get_partner().is_company |
||||
|
|
||||
|
@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 |
||||
|
|
||||
|
@api.model |
||||
|
def _get_possible_share(self): |
||||
|
domain = [('is_share','=',True)] |
||||
|
partner = self._get_partner() |
||||
|
if partner.is_company: |
||||
|
domain.append(('by_company','=',True)) |
||||
|
else: |
||||
|
domain.append(('by_individual','=',True)) |
||||
|
|
||||
|
return domain |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends('share_product', 'share_qty') |
||||
|
def _compute_subscription_amount(self): |
||||
|
for sub_request in self: |
||||
|
sub_request.subscription_amount = sub_request.share_product.list_price * sub_request.share_qty |
||||
|
|
||||
|
is_company = fields.Boolean(String="Is company?", default=_get_is_company) |
||||
|
cooperator = fields.Many2one('res.partner', string="Cooperator", default=_get_partner) |
||||
|
register_number = fields.Char(string="Register Number", required=True, default=_get_register_number) |
||||
|
share_product = fields.Many2one('product.product', string='Share Type', domain=lambda self: self._get_possible_share(),\ |
||||
|
default=_default_product_id, required=True) |
||||
|
share_qty = fields.Integer(string="Share Quantity", required=True) |
||||
|
share_unit_price = fields.Float(related='share_product.list_price', string='Share price', readonly=True) |
||||
|
subscription_amount = fields.Float(compute='_compute_subscription_amount', string='Subscription amount', digits=dp.get_precision('Account'), readonly=True) |
||||
|
|
||||
|
@api.multi |
||||
|
def create_subscription(self): |
||||
|
sub_req = self.env['subscription.request'] |
||||
|
cooperator = self.cooperator |
||||
|
vals = {'partner_id': cooperator.id, |
||||
|
'name': cooperator.name, |
||||
|
'share_product_id':self.share_product.id, |
||||
|
'ordered_parts':self.share_qty, |
||||
|
'user_id':self.env.uid} |
||||
|
if self.is_company: |
||||
|
vals['company_register_number'] = self.register_number |
||||
|
else: |
||||
|
vals['no_registre'] = self.register_number |
||||
|
|
||||
|
if not self._get_register_number(): |
||||
|
if self.is_company: |
||||
|
cooperator.write({'company_register_number':self.register_number}) |
||||
|
else: |
||||
|
if sub_req.check_belgian_identification_id(self.register_number): |
||||
|
cooperator.write({'national_register_number':self.register_number}) |
||||
|
else: |
||||
|
raise UserError(_("The national register number is not valid.")) |
||||
|
|
||||
|
sub_req.create(vals) |
||||
|
return {'type': 'ir.actions.act_window_close'} |
||||
|
|
@ -0,0 +1,40 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record id="view_create_subscription" model="ir.ui.view"> |
||||
|
<field name="name">Create Subscription</field> |
||||
|
<field name="model">partner.create.subscription</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Create Subscription"> |
||||
|
<p class="oe_grey"> |
||||
|
Subscription request will be created with data from the partner. |
||||
|
</p> |
||||
|
<group> |
||||
|
<field name="is_company" invisible="True"/> |
||||
|
<field name="cooperator" invisible="True"/> |
||||
|
<field name="register_number"/> |
||||
|
<field name="share_product" widget="selection"/> |
||||
|
<field name="share_qty"/> |
||||
|
<field name="share_unit_price"/> |
||||
|
<field name="subscription_amount"/> |
||||
|
</group> |
||||
|
<footer> |
||||
|
<button name="create_subscription" string="Create Subscription" type="object" class="btn-primary"/> |
||||
|
<button string="Cancel" class="btn-default" special="cancel"/> |
||||
|
</footer> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
<record id="action_view_create_subscription" model="ir.actions.act_window"> |
||||
|
<field name="name">Create Subscription</field> |
||||
|
<field name="type">ir.actions.act_window</field> |
||||
|
<field name="res_model">partner.create.subscription</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_user'))]"/> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue