콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
16921 화면

I need to pass the value of my two fields i.e date_from n date_to from my wizard to the report it calls/prints. Following is my code. This is working fine but only problem is i am not able to find how to print these two fields. Any help is appreciated.

class my_wizard_report(osv.osv_memory):

    _name = 'my.wizard.report'
##    _inherit = 'account.invoice'
    _description = 'Test Report'  

    _columns = {
        'date_from':fields.date('Date From',store=True),
        'date_to':fields.date('Date To',store=True),
        'invoice_ids':fields.many2many('account.invoice', string='Filter on invoices',help="Only selected invoices will be printed"),
    }

    _defaults = {
        'date_from': lambda *a: time.strftime('%Y-%m-%d'),
        'date_to': lambda *a: time.strftime('%Y-%m-%d'),
    }

    def print_report(self, cr, uid, ids, context=None):
        datas = {}
        if context is None:
            context = {}
        data = self.read(cr, uid, ids,['date_from', 'date_to', 'invoice_ids'], context=context)
        date_from = data[0]['date_from'] 
        date_to = data[0]['date_to']
        obj = self.pool.get('account.invoice')
        ids = obj.search(cr, uid, [('date_invoice','>=',date_from),('date_invoice','<=',date_to)])
        datas = {
                 'ids': ids,
                 'model': 'account.invoice',
                 'form': data
                }
        return {'type': 'ir.actions.report.xml', 'report_name': 'account.invoice.rnd5c3tV', 'datas': datas}





my_wizard_report()



<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

<!-- cancel order  -->

        <record id="view_my_wiz_form" model="ir.ui.view">
            <field name="name">print.report.form</field>
            <field name="model">my.wizard.report</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Print Report">
                    <group colspan="4" >
                        <field name="date_from" filter_domain="[('date_invoice','&gt;=',self)]" />
                        <field name="date_to" filter_domain="[('date_invoice','&lt;=',self)]"  />
                    </group>
                        <separator string="Print Only" colspan="4" />
                        <group colspan = "4">
                            <field name="invoice_ids" colspan="4" nolabel="1"/>
                        </group>
                    <group colspan="4" col="6">                     
                        <button  icon="gtk-ok" name="print_report" string="Print" type="object"/>
                   </group>
               </form>
            </field>
        </record>

        <record id="action_my_wiz_form" model="ir.actions.act_window">
            <field name="name">Print Report</field>
            <field name="res_model">my.wizard.report</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
           <field name="view_id" ref="view_my_wiz_form"/>
           <field name="target">new</field>        
        </record>

        <act_window id="action_my_wiz_form_values"
            key2="client_action_multi" name="Print Report"
            res_model="my.wizard.report" src_model="add.penalty"
            view_mode="form" target="new" view_type="form"/>

    </data>
</openerp>

C:\fakepath\screen2.png

C:\fakepath\screen1.png

C:\fakepath\reports.png

아바타
취소
베스트 답변

Use data = self.read(cr, uid, ids,)[-1] in your print_report method and you will get the details that you entered via the wizard. It will a dictionary in which you will have keys and values as per the above defined fields

아바타
취소
베스트 답변
I didnt understand your requirement properly, If you want to print something you can use
import logging 
_logger = logging.getLogger(__name__)
_logger.info('Create a with vals ..............................%s', res)
Is that your requirement?
아바타
취소
작성자

I don't understand what you said above but my requirement is very simple. The report is created by me already using Openoffice(base report designer) then i created a wizard in my custom module, i defined two fields date_from and date_to on the wizard and whatever dates are selected there i want to print them on my report which i called from here. Now its clear i hope. Please let me know if you have a solution to it.

작성자

I added few screen shots above.

@evon sorry I dnt have any idea :(

베스트 답변

I copy the code from sale.py that I edited to send some fields to my invoice.

   def _prepare_invoice(self, cr, uid, order, lines, context=None):
    """Prepare the dict of values to create the new invoice for a
       sales order. This method may be overridden to implement custom
       invoice generation (making sure to call super() to establish
       a clean extension chain).

       :param browse_record order: sale.order record to invoice
       :param list(int) line: list of invoice line IDs that must be
                              attached to the invoice
       :return: dict of value to create() the invoice
    """
    if context is None:
        context = {}
    journal_ids = self.pool.get('account.journal').search(cr, uid,
        [('type', '=', 'sale'), ('company_id', '=', order.company_id.id)],
        limit=1)
    if not journal_ids:
        raise osv.except_osv(_('Error!'),
            _('Please define sales journal for this company: "%s" (id:%d).') % (order.company_id.name, order.company_id.id))
    invoice_vals = {
        'name': order.client_order_ref or '',
        'origin': order.name,
        'type': 'out_invoice',
        'reference': order.client_order_ref or order.name,
        'account_id': order.partner_id.property_account_receivable.id,
        'partner_id': order.partner_invoice_id.id,
        'journal_id': journal_ids[0],
        'invoice_line': [(6, 0, lines)],
        'currency_id': order.pricelist_id.currency_id.id,
        'comment': order.note,
        'payment_term': order.payment_term and order.payment_term.id or False,
        'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
        'date_invoice': context.get('date_invoice', False),
        'company_id': order.company_id.id,
        'user_id': order.user_id and order.user_id.id or False,
        'x_destplace': order.x_destplace,
        'x_loadplace': order.x_loadplace,
        'x_vehivle': order.x_vehicle
    }

    # Care for deprecated _inv_get() hook - FIXME: to be removed after 6.1
    invoice_vals.update(self._inv_get(cr, uid, order, context=context))
    return invoice_vals

I 've added the x_ fields in both models (sales.order and account.invoice) and with this addition to the code (in invoice_vals) it just copies their values. So if you want to send those values to your invoice and then print it you have to create something like a _prepare_invoice function.

아바타
취소
작성자

the account.invoice model doesn't contain these fields, these are in the wizard.

Ah then you have to send those fields from your form to the account.invoice. Wait a minute I 'll copy a code.

sry I dont know how to post a code clearly

Also check this video http://www.youtube.com/watch?v=5dDoPcm6pVM

관련 게시물 답글 화면 활동
0
3월 15
3893
1
3월 15
10188
2
7월 24
3109
2
4월 24
2915
4
10월 20
5840