Skip to Content
Menu
This question has been flagged
1 Reply
5291 Views

Hi,

I want to display  all Shipping address and there Sales Order Name ,and total when we select a customer ,from_date and to_date ,How I can show? i have created like below


class CustomerReportDetails(models.TransientModel):

_name = 'customer.report'

@api.depends('partner_shipping_id','from_date','to_date')

 def get_shipping_details(self):

if self.partner_shipping_id:

for x in self.env['res.partner'].search([('id', '=', self.partner_shipping_id.id)]):

# type_search=

print 'iddddddd',x.child_ids.ids

#######Here How to change my code########

Here need to filter all the shipping address of this customer and based on that shipping address need to find all the 

sales order with status 



partner_shipping_id = fields.Many2one('res.partner','Customer')

from_date = fields.Date('From')

to_date = fields.Date('To')

shipping_address_ids=fields.One2many('shipping.address.line','shiping_id','Branch Sales

Details',compute=get_shipping_details)


class ExpiryProductLines(models.TransientModel):

_name='shipping.address.line'

shiping_id=fields.Many2one('customer.report')

partner_shipping_id=fields.Many2one('res.partner','Branch')

total_sale_amount=fields.Float('Amount')

status_invoice=fields.Char('Status')

This is my code..




--------------------------------------------XML-----------------------------------------------


    <record model="ir.ui.view" id="shipping_customer_report_wiz">

<field name="name">BranchWise Sales Report</field>

<field name="model">customer.report</field>

<field name="arch" type="xml">

<form create="false">

<group>

<group>

<field name="partner_shipping_id" domain="[('is_head_office', '=','True')]"/>

</group>

<group>

<field name="from_date"/>

<field name="to_date"/>

</group>

</group>

<field name='shipping_address_ids'>

<tree>

<field name='partner_shipping_id'/>

<field name='total_sale_amount'/>

<!--<field name='status_invoice'/>-->

</tree>

</field>

<footer>

<button name="print_report" type="object"

string="Print Report" class="oe_highlight" style="margin-left: 5px;"/>

</footer>

</form>

</field>

</record>

<record model="ir.actions.act_window" id="action_branchwise_reports">

<field name="name">Branchwise Details</field>

<field name="res_model">customer.report</field>

<field name="target">new</field>

<field name="view_mode">form</field>

</record>

<menuitem name="Branchwise Sales Details "

id="report_wizard_branchwise"

sequence="30"

parent="sales_team.menu_sales"

action="action_branchwise_reports"

/>


Avatar
Discard
Best Answer

You could try something like this

@api.onchange('partner_shipping_id','from_date','to_date')

def get_shipping_details(self):

if self.partner_shipping_id:

order_ids = self.env['sale.order'].search([('partner_id', '=', self.partner_shipping_id.id), ('date_order', '>=', self.from_date), ('date_order', '<=', self.to_date)])

self.shipping_address_ids = [(0,0, {

'partner_shipping_id': order.partner_shipping_id.id,

'total_sale_amount': order.amount_total, # change this field value if apply to match another

'status_invoice': order.state, # change this field value if apply to match another

}) for order in order_ids]

else:

self.shipping_address_ids = [(6,0,[])]

Hope this helps. Maybe it needs some tweaks but the idea is there

Best Regards

Avatar
Discard