This question has been flagged
2477 Views

Hi all,

Here I attached my code and scenario .What I required .I want to send mail to customer and salesperson for every month with some cost details and product details------

This is my code--

product_info.py

# -*- coding: utf-8 -*-
##############################################################################
#    
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    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/>.     
#
##############################################################################

# TODO:
#   Error treatment: exception, request, ... -> send request to user_id
from openerp.osv import fields,osv


###################################################

#inherit product.product model and add fields for different subscription types#
###################################################

class product_product(osv.osv):
    
    _inherit='product.product'
    
    _columns={
              'setup_cost':fields.float('setup-cost',required=True),
              'monthly_cost':fields.float('monthly-cost',required=True),
              'quarterly_cost':fields.float('quarterly-cost',required=True),
              'half_yearly':fields.float('half-yearly-cost',required=True),
              'yearly':fields.float('yearly-cost',required=True)
              }
product_product()

class sale_order_line(osv.osv):
     
    _inherit='sale.order.line'
     
    _columns={
            'payment_type':fields.selection([('fixprice','Fix price '),
                                        ('sub monthly','Subscription monthly'),
                                       ('sub quarter','Subscription quarterly'),
                                       ('sub half','Subscription half yearly')],'Payment type')
            
              }
    
product_product()


class account_invoice_line(osv.osv):
     
   _inherit='account.invoice.line'
   
   _columns={
#             'payment_type':fields.selection([('fixprice','Fix price '),
#                                         ('sub monthly','Subscription monthly  '),
#                                        ('sub quarter','Subscription quarterly  '),
#                                        ('sub half','Subscription half yearly ')],'Payment type')

            'payment_type':fields.char('Subscription Cost'),
             'monthlyin_cost':fields.float('monthly-cost',required=True),
              'quarterlyin_cost':fields.float('quarterly-cost',required=True),
              'halfin_yearly':fields.float('half-yearly-cost',required=True),
              'yearlyin':fields.float('yearly-cost',required=True)
              }
   
   
   def product_id_change(self, cr, uid, ids, product,uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, context=None, company_id=None):
        sub_val=self.pool.get('product.product').browse(cr,uid,product)
        
        #ean_val=self.pool.get('product.product').read(cr,uid,ids,['ean13'],context=context)
        #print "###############################ean_val",ean_val
        #print "###############################eanval##########",ean_val.ean13.id
        if context is None:
            context = {}
        company_id = company_id if company_id != None else context.get('company_id',False)
        context = dict(context)
        context.update({'company_id': company_id, 'force_company': company_id})
        if not partner_id:
            raise osv.except_osv(_('No Partner Defined!'),_("You must first select a partner!") )
        if not product:
            if type in ('in_invoice', 'in_refund'):
                return {'value': {}, 'domain':{'product_uom':[]}}
            else:
                return {'value': {'price_unit': 0.0}, 'domain':{'product_uom':[]}}
        part = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
        fpos_obj = self.pool.get('account.fiscal.position')
        fpos = fposition_id and fpos_obj.browse(cr, uid, fposition_id, context=context) or False

        if part.lang:
            context.update({'lang': part.lang})
        result = {}
        res = self.pool.get('product.product').browse(cr, uid, product, context=context)

        if type in ('out_invoice','out_refund'):
            a = res.property_account_income.id
            if not a:
                a = res.categ_id.property_account_income_categ.id
        else:
            a = res.property_account_expense.id
            if not a:
                a = res.categ_id.property_account_expense_categ.id
        a = fpos_obj.map_account(cr, uid, fpos, a)
        if a:
            result['account_id'] = a

        if type in ('out_invoice', 'out_refund'):
            taxes = res.taxes_id and res.taxes_id or (a and self.pool.get('account.account').browse(cr, uid, a, context=context).tax_ids or False)
        else:
            taxes = res.supplier_taxes_id and res.supplier_taxes_id or (a and self.pool.get('account.account').browse(cr, uid, a, context=context).tax_ids or False)
        tax_id = fpos_obj.map_tax(cr, uid, fpos, taxes)

        if type in ('in_invoice', 'in_refund'):
            result.update( {'price_unit': price_unit or res.standard_price,'invoice_line_tax_id': tax_id} )
        else:
            result.update({'price_unit': res.list_price, 'invoice_line_tax_id': tax_id,'payment_type':sub_val.setup_cost,'monthlyin_cost':sub_val.monthly_cost,'quarterlyin_cost':sub_val.quarterly_cost,'halfin_yearly':sub_val.half_yearly,'yearlyin':sub_val.yearly})
        result['name'] = res.partner_ref

        result['uos_id'] = uom_id or res.uom_id.id
        if res.description:
            result['name'] += '\n'+res.description

        domain = {'uos_id':[('category_id','=',res.uom_id.category_id.id)]}

        res_final = {'value':result, 'domain':domain}

        if not company_id or not currency_id:
            return res_final

        company = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
        currency = self.pool.get('res.currency').browse(cr, uid, currency_id, context=context)

        if company.currency_id.id != currency.id:
            if type in ('in_invoice', 'in_refund'):
                res_final['value']['price_unit'] = res.standard_price
            new_price = res_final['value']['price_unit'] * currency.rate
            res_final['value']['price_unit'] = new_price

        if result['uos_id'] and result['uos_id'] != res.uom_id.id:
            selected_uom = self.pool.get('product.uom').browse(cr, uid, result['uos_id'], context=context)
            new_price = self.pool.get('product.uom')._compute_price(cr, uid, res.uom_id.id, res_final['value']['price_unit'], result['uos_id'])
            res_final['value']['price_unit'] = new_price
        return res_final
    
#     def onchange_schemid(self,cr,uid,ids,price_unit,quantity,context=None):
#             if price_unit:
#                 amount_new=price_unit*quantity
#                 return {'value':{'new_total':amount_new}}
#             return {}
         
#     def onchange_tax_id(self,cr,uid,ids,invoice_line_tax_id,context=None):
#         a=self.pool.get('account.invoice.line').read(cr,uid,['new_total'],context=context)
#         b=self.pool.get('account.tax').read(cr,uid,['invoice_line_tax_id'],context=context)
#         if invoice_line_tax_id:
#                 val1=a[0]['new_total']
#                 val2=b[0]['invoice_line_tax_id']
#                 amount_with_tax=val1+val2
#                 return {'value':{'new_with_tax':amount_with_tax}}
#         return {}
    
account_invoice_line()
   
#account_invoice_line()
    
    
#     def send_subscription_invoice_(self, cr, uid, ids, context=None):
#       
#         print "inside send method#############################"
#         ir_model_data = self.pool.get('ir.model.data')
#         try:
#                 compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1]
#         except ValueError:
#                 compose_form_id = False
#                 return {
#                 'type': 'ir.actions.act_window',
#                 'view_type': 'form',
#                 'view_mode': 'form',
#                 'res_model': 'mail.compose.message',
#                 'views': [(compose_form_id, 'form')],
#                 'view_id': compose_form_id,
#                 'target': 'new',
#                 'context': {},
#             }
#        
    


###################################################

#Define model for Payment types for different schemes
###################################################

class payment_type(osv.osv):
     
    _name='payment.type'
     
    _columns={
              'name':fields.char('name'),
              'id':fields.integer('ID')
            
              }
    
    
payment_type()

 

###################################################

#move sale order to invoice

#3.    Reminder will be sent to the customer and the sales person for collection as an email during the period.


###################################################


###################################################

#Some functional configuration is required for completing
#with server action and automated action feature..
 #this task also I am using openerp subscription module

###################################################

 

 

.xml file

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
    
    <record id="product_form_inherited" model="ir.ui.view">
            <field name="name">product.form.inherited</field>
            <field name="model">product.product</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                
            <xpath expr="/form/sheet/notebook/page[@string='Sales']" position="after">
                <page string="Subscription prices">
                                <group>    <field name="setup_cost"/>
                                    <field name="monthly_cost"/>
                                    <field name="quarterly_cost"/>
                                    <field name="half_yearly"/>
                                    <field name="yearly"/>
                                    </group>
                        </page>
            </xpath>
            

        </field>
        </record>
        
        
        <record id="product_form_view_sub" model="ir.ui.view">
        <field name="name">product.form.view.sub</field>
        <field name="model">payment.type</field>
        <field name="arch" type="xml">
        <form string="Product form" version="7.0">
<sheet>
    
        <group><field name="id" invisible="1"/>
        <field name="name"/></group>
</sheet>

        </form>
        
        </field>
</record>

 <record id="product_tree_view_sub" model="ir.ui.view">
        <field name="name">product.tree.view.sub</field>
        <field name="model">payment.type</field>
        <field name="arch" type="xml">
        <tree string="Product form">

    
        <field name="id" />
        <field name="name"/>


        </tree>
        </field>
</record>

         <record id="saleline_view_inherited" model="ir.ui.view">
                <field name="name">sale_line</field>
                <field name="model">sale.order</field>
                <field name="type">form</field>
                <field name="inherit_id" ref="sale.view_order_form"/>
                <field name="arch" type="xml">
                
                    <xpath expr="/form/sheet/notebook/page/field/tree/field[@name='product_id']" position="after">
                        <field name="payment_type"/>
                        
                    </xpath>
                    
                </field>
                </record>
                
                
                <record id="accountline_view_inherited" model="ir.ui.view">
                <field name="name">account_line</field>
                <field name="model">account.invoice</field>
                <field name="type">form</field>
                <field name="inherit_id" ref="account.invoice_form"/>
                <field name="arch" type="xml">
                
                    <xpath expr="/form/sheet/notebook/page/field/tree/field[@name='product_id']" position="after">
                        <field name="payment_type"/>
                        <field name="monthlyin_cost"/>
                        <field name="quarterlyin_cost"/>
                        <field name="halfin_yearly"/>
                        <field name="yearlyin"/>
                    </xpath>
                    
                    <xpath expr="/form/sheet/notebook/page/field/tree/field[@name='name']" invisible="1">
                        
                    </xpath>
                    
                    <!-- <xpath expr="/form/sheet/notebook/page[1]/field[1]/tree/field" position="after">
                        <field name="payment_type"/>
                    </xpath> -->
                    
                </field>
                </record>
        
        
    </data>
</openerp>


.openerp.py------

# -*- coding: utf-8 -*-
##############################################################################
#    
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    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/>.     
#
##############################################################################
{
'name':'Subscription Form',
'version':'0.0',
'author':'Libu Koshy 8281867236',
'depends':['base','product','sale'],
'update_xml' : ['product_change_view.xml'
                                ],
'installable':True,
'category':'General',
'description':'1. Subscription pricing Module ',
'website':'http://www.mycompanies.com',
'demo':[]
}

What i required is i want to send an automated invoice to customer and sale person when we create a invoice with this data

'payment_type':fields.char('Subscription Cost'),
             'monthlyin_cost':fields.float('monthly-cost',required=True),
              'quarterlyin_cost':fields.float('quarterly-cost',required=True),
              'halfin_yearly':fields.float('half-yearly-cost',required=True),
              'yearlyin':fields.float('yearly-cost',required=True)

    
    

 

 

Avatar
Discard