from netforce.model import Model, get_model from netforce.access import get_active_company class ReportStockCard(Model): _inherit="report.stock.card" def write(self,ids,vals,**kw): kw['check_time']=False super().write(ids,vals,**kw) def get_report_data(self,ids,context={}): company=get_model("company").browse(get_active_company()) defaults=self.default_get(context=context) location_id=defaults.get("location_id") date_from=defaults.get('date_from') date_to=defaults.get('date_to') #product_id=defaults.get('product_id') if not ids and not location_id: return { 'date_from': date_from, 'date_to': date_to, 'company_name': company.name, } data={ 'loc_view': False, } if ids: obj=self.browse(ids)[0] location=obj.location_id loc_view_id=location.id if location.type=='view': data.update({ 'loc_view': True, 'date_from': obj.date_from, 'date_to': obj.date_to, 'company_name': company.name, }) child_ids=get_model('stock.location').search([['parent_id','=',location.id]]) locs={} for child_id in child_ids: obj.write({ 'location_id': child_id, }) groups=super().get_report_data(ids,context)['groups'] for group in groups: location_id=group['location_id'] locs.setdefault(location_id,{ 'total_in_amount': 0, 'total_in_qty': 0, 'total_in_qty2': 0, 'total_out_amount': 0, 'total_out_qty': 0, 'total_out_qty2': 0, }) locs[location_id]['total_in_amount']+=group['total_in_amount'] locs[location_id]['total_in_qty']+=group['total_in_qty'] locs[location_id]['total_in_qty2']+=group['total_in_qty2'] locs[location_id]['total_out_amount']+=group['total_out_amount'] locs[location_id]['total_out_qty']+=group['total_out_qty'] locs[location_id]['total_out_qty2']+=group['total_out_qty2'] lines=[] for loc_id,vals in locs.items(): vals['total_bl_qty']=vals['total_in_qty']-vals['total_out_qty'] vals['total_bl_amount']=vals['total_in_amount']-vals['total_out_amount'] vals['total_bl_qty2']=vals['total_in_qty2']-vals['total_out_qty2'] location=get_model('stock.location').browse(loc_id) vals.update({ 'loc_id': loc_id, 'loc_name': location.name, }) lines.append(vals) obj.write({ 'location_id': loc_view_id, }) data.update({ 'lines': lines, 'show_qty2': True, }) else: data.update(super().get_report_data(ids,context)) else: data.update(super().get_report_data(ids,context)) return data ReportStockCard.register()