Large cleanups in addons
The code I merged in my branch stat buttons was sadly not up to our standing... This branch improves the situation by removing harmful try/excpet/pass statements, by using search_count when appropriate, by removing unused one2many fields and by correcting some bugs bzr revid: ged@openerp.com-20140507151749-k37iclwt499ip3e4
This commit is contained in:
commit
9086f5b613
|
@ -172,18 +172,15 @@ class res_partner(osv.osv):
|
|||
return result
|
||||
|
||||
def _journal_item_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,{'journal_item_count': 0, 'contracts_count': 0 }), ids))
|
||||
|
||||
# the user may not have access rights
|
||||
try:
|
||||
for partner in self.browse(cr, uid, ids, context=context):
|
||||
res[partner.id] = {
|
||||
'journal_item_count': len(partner.journal_item_ids),
|
||||
'contracts_count': len(partner.contract_ids)
|
||||
}
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
MoveLine = self.pool('account.move.line')
|
||||
AnalyticAccount = self.pool('account.analytic.account')
|
||||
return {
|
||||
partner_id: {
|
||||
'journal_item_count': MoveLine.search_count(cr, uid, [('partner_id', '=', partner_id)], context=context),
|
||||
'contracts_count': AnalyticAccount.search_count(cr,uid, [('partner_id', '=', partner_id)], context=context)
|
||||
}
|
||||
for partner_id in ids
|
||||
}
|
||||
|
||||
def has_something_to_reconcile(self, cr, uid, partner_id, context=None):
|
||||
'''
|
||||
|
@ -215,7 +212,6 @@ class res_partner(osv.osv):
|
|||
'debit_limit': fields.float('Payable Limit'),
|
||||
'total_invoiced': fields.function(_invoice_total, string="Total Invoiced", type='float'),
|
||||
'contracts_count': fields.function(_journal_item_count, string="Contracts", type='integer', multi="invoice_journal"),
|
||||
'journal_item_ids': fields.one2many('account.move.line', 'partner_id', 'Journal Items'),
|
||||
'journal_item_count': fields.function(_journal_item_count, string="Journal Items", type="integer", multi="invoice_journal"),
|
||||
'property_account_payable': fields.property(
|
||||
type='many2one',
|
||||
|
|
|
@ -117,15 +117,12 @@ class sale_order_line(osv.osv):
|
|||
class product_product(osv.Model):
|
||||
_inherit = 'product.product'
|
||||
def _rules_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for rule in self.browse(cr, uid, ids, context=context):
|
||||
res[rule.id] = len(rule.rules_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Analytic = self.pool['account.analytic.default']
|
||||
return {
|
||||
product_id: Analytic.search_count(cr, uid, [('product_id', '=', product_id)], context=context)
|
||||
for product_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'rules_ids': fields.one2many('account.analytic.default', 'product_id', 'Analytic Rules '),
|
||||
'rules_count': fields.function(_rules_count, string='# Analytic Rules', type='integer'),
|
||||
}
|
||||
|
||||
|
|
|
@ -238,13 +238,11 @@ class account_asset_asset(osv.osv):
|
|||
val['value_residual'] = purchase_value - salvage_value
|
||||
return {'value': val}
|
||||
def _entry_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for entry in self.browse(cr, uid, ids, context=context):
|
||||
res[entry.id] = len(entry.account_move_line_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
MoveLine = self.pool('account.move.line')
|
||||
return {
|
||||
asset_id: MoveLine.search_count(cr, uid, [('asset_id', '=', asset_id)], context=context)
|
||||
for asset_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'account_move_line_ids': fields.one2many('account.move.line', 'asset_id', 'Entries', readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'entry_count': fields.function(_entry_count, string='# Asset Entries', type='integer'),
|
||||
|
|
|
@ -216,13 +216,11 @@ class crm_lead(format_address, osv.osv):
|
|||
res[lead.id][field] = abs(int(duration))
|
||||
return res
|
||||
def _meeting_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for meeting in self.browse(cr, uid, ids, context=context):
|
||||
res[meeting.id] = len(meeting.meeting_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Event = self.pool['calendar.event']
|
||||
return {
|
||||
opp_id: Event.search_count(cr,uid, [('opportunity_id', '=', opp_id)], context=context)
|
||||
for opp_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'partner_id': fields.many2one('res.partner', 'Partner', ondelete='set null', track_visibility='onchange',
|
||||
select=True, help="Linked partner (optional). Usually created when converting the lead."),
|
||||
|
@ -297,7 +295,6 @@ class crm_lead(format_address, osv.osv):
|
|||
'payment_mode': fields.many2one('crm.payment.mode', 'Payment Mode', \
|
||||
domain="[('section_id','=',section_id)]"),
|
||||
'planned_cost': fields.float('Planned Costs'),
|
||||
'meeting_ids': fields.one2many('calendar.event', 'opportunity_id', 'Opportunities'),
|
||||
'meeting_count': fields.function(_meeting_count, string='# Meetings', type='integer'),
|
||||
}
|
||||
|
||||
|
|
|
@ -32,14 +32,6 @@ class crm_phonecall(osv.osv):
|
|||
_order = "id desc"
|
||||
_inherit = ['mail.thread']
|
||||
|
||||
def _meeting_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for meeting in self.browse(cr, uid, ids, context=context):
|
||||
res[meeting.id] = len(meeting.meeting_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
_columns = {
|
||||
'date_action_last': fields.datetime('Last Action', readonly=1),
|
||||
'date_action_next': fields.datetime('Next Action', readonly=1),
|
||||
|
@ -74,8 +66,6 @@ class crm_phonecall(osv.osv):
|
|||
'date_closed': fields.datetime('Closed', readonly=True),
|
||||
'date': fields.datetime('Date'),
|
||||
'opportunity_id': fields.many2one ('crm.lead', 'Lead/Opportunity'),
|
||||
'meeting_ids': fields.one2many('calendar.event', 'phonecall_id', 'Phonecalls'),
|
||||
'meeting_count': fields.function(_meeting_count, string='# Meetings', type='integer'),
|
||||
}
|
||||
|
||||
def _get_default_state(self, cr, uid, context=None):
|
||||
|
|
|
@ -33,10 +33,11 @@ class res_partner(osv.osv):
|
|||
res[partner.id] = {
|
||||
'opportunity_count': len(partner.opportunity_ids),
|
||||
'meeting_count': len(partner.meeting_ids),
|
||||
'phonecall_count': len(partner.meeting_ids),
|
||||
}
|
||||
except:
|
||||
pass
|
||||
for partner in self.browse(cr, uid, ids, context):
|
||||
res[partner.id]['phonecall_count'] = len(partner.phonecall_ids)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
|
|
|
@ -191,15 +191,13 @@ class crm_claim(osv.osv):
|
|||
class res_partner(osv.osv):
|
||||
_inherit = 'res.partner'
|
||||
def _claim_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for partner in self.browse(cr, uid, ids, context=context):
|
||||
res[partner.id] = len(partner.claims_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Claim = self.pool['crm.claim']
|
||||
return {
|
||||
partner_id: Claim.search_count(cr,uid, [('partner_id', '=', partner_id)], context=context)
|
||||
for partner_id in ids
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'claims_ids': fields.one2many('crm.claim', 'partner_id', 'Claims'),
|
||||
'claim_count': fields.function(_claim_count, string='# Claims', type='integer'),
|
||||
}
|
||||
|
||||
|
|
|
@ -315,18 +315,21 @@ class fleet_vehicle(osv.Model):
|
|||
return model_id
|
||||
|
||||
def _count_all(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,{'odometer_count': 0, 'fuel_logs_count': 0, 'service_count': 0, 'contract_count': 0, 'cost_count': 0,}), ids))
|
||||
try:
|
||||
for costs in self.browse(cr, uid, ids, context=context):
|
||||
res[costs.id] = {'odometer_count': len(costs.odometer_ids),
|
||||
'fuel_logs_count': len(costs.log_fuel),
|
||||
'service_count': len(costs.log_services),
|
||||
'contract_count': len(costs.log_contracts),
|
||||
'cost_count': len(costs.costs_ids)
|
||||
}
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Odometer = self.pool['fleet.vehicle.odometer']
|
||||
LogFuel = self.pool['fleet.vehicle.log.fuel']
|
||||
LogService = self.pool['fleet.vehicle.log.services']
|
||||
LogContract = self.pool['fleet.vehicle.log.contract']
|
||||
Cost = self.pool['fleet.vehicle.cost']
|
||||
return {
|
||||
vehicle_id: {
|
||||
'odometer_count': Odometer.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
|
||||
'fuel_logs_count': LogFuel.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
|
||||
'service_count': LogService.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
|
||||
'contract_count': LogContract.search_count(cr, uid, [('vehicle_id', '=', vehicle_id)], context=context),
|
||||
'cost_count': Cost.search_count(cr, uid, [('vehicle_id', '=', vehicle_id), ('parent_id', '=', False)], context=context)
|
||||
}
|
||||
for vehicle_id in ids
|
||||
}
|
||||
|
||||
_name = 'fleet.vehicle'
|
||||
_description = 'Information on a vehicle'
|
||||
|
@ -341,8 +344,6 @@ class fleet_vehicle(osv.Model):
|
|||
'log_fuel': fields.one2many('fleet.vehicle.log.fuel', 'vehicle_id', 'Fuel Logs'),
|
||||
'log_services': fields.one2many('fleet.vehicle.log.services', 'vehicle_id', 'Services Logs'),
|
||||
'log_contracts': fields.one2many('fleet.vehicle.log.contract', 'vehicle_id', 'Contracts'),
|
||||
'costs_ids': fields.one2many('fleet.vehicle.cost', 'vehicle_id', 'Costs'),
|
||||
'odometer_ids': fields.one2many('fleet.vehicle.odometer', 'vehicle_id', 'Odometer'),
|
||||
'cost_count': fields.function(_count_all, type='integer', string="Costs" , multi=True),
|
||||
'contract_count': fields.function(_count_all, type='integer', string='Contracts', multi=True),
|
||||
'service_count': fields.function(_count_all, type='integer', string='Services', multi=True),
|
||||
|
|
|
@ -39,13 +39,11 @@ class hr_employee(osv.osv):
|
|||
return res
|
||||
|
||||
def _contracts_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for employee in self.browse(cr, uid, ids, context=context):
|
||||
res[employee.id] = len(employee.contract_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Contract = self.pool['hr.contract']
|
||||
return {
|
||||
employee_id: Contract.search_count(cr,uid, [('employee_id', '=', employee_id)], context=context)
|
||||
for employee_id in ids
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'manager': fields.boolean('Is a Manager'),
|
||||
|
|
|
@ -104,19 +104,15 @@ class hr_employee(osv.Model):
|
|||
_inherit="hr.employee"
|
||||
|
||||
def _appraisal_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for employee in self.browse(cr, uid, ids, context=context):
|
||||
res[employee.id] = len(employee.appraisal_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
|
||||
Evaluation = self.pool['hr.evaluation.interview']
|
||||
return {
|
||||
employee_id: Evaluation.search_count(cr, uid, [('user_to_review_id', '=', employee_id)], context=context)
|
||||
for employee_id in ids
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'evaluation_plan_id': fields.many2one('hr_evaluation.plan', 'Appraisal Plan'),
|
||||
'evaluation_date': fields.date('Next Appraisal Date', help="The date of the next appraisal is computed by the appraisal plan's dates (first appraisal + periodicity)."),
|
||||
'appraisal_ids': fields.one2many('hr.evaluation.interview', 'user_to_review_id', 'Appraisal Interviews'),
|
||||
'appraisal_count': fields.function(_appraisal_count, type='integer', string='Appraisal Interviews'),
|
||||
}
|
||||
|
||||
|
|
|
@ -550,13 +550,11 @@ class hr_employee(osv.osv):
|
|||
return result
|
||||
|
||||
def _leaves_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for employee in self.browse(cr, uid, ids, context=context):
|
||||
res[employee.id] = len(employee.leave_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Holidays = self.pool['hr.holidays']
|
||||
return {
|
||||
employee_id: Holidays.search_count(cr,uid, [('employee_id', '=', employee_id)], context=context)
|
||||
for employee_id in ids
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'remaining_leaves': fields.function(_get_remaining_days, string='Remaining Legal Leaves', fnct_inv=_set_remaining_days, type="float", help='Total number of legal leaves allocated to this employee, change this value to create allocation/leave request. Total based on all the leave types without overriding limit.'),
|
||||
|
@ -566,7 +564,6 @@ class hr_employee(osv.osv):
|
|||
'current_leave_id': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Type",type='many2one', relation='hr.holidays.status'),
|
||||
'leave_date_from': fields.function(_get_leave_status, multi='leave_status', type='date', string='From Date'),
|
||||
'leave_date_to': fields.function(_get_leave_status, multi='leave_status', type='date', string='To Date'),
|
||||
'leave_ids': fields.one2many('hr.holidays', 'employee_id', 'Leaves'),
|
||||
'leaves_count': fields.function(_leaves_count, type='integer', string='Leaves'),
|
||||
|
||||
}
|
||||
|
|
|
@ -261,11 +261,8 @@ class hr_payslip(osv.osv):
|
|||
|
||||
def _count_detail_payslip(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = {}
|
||||
try:
|
||||
for details in self.browse(cr, uid, ids, context=context):
|
||||
res[details.id] = len(details.line_ids)
|
||||
except:
|
||||
pass
|
||||
for details in self.browse(cr, uid, ids, context=context):
|
||||
res[details.id] = len(details.line_ids)
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
|
@ -285,7 +282,6 @@ class hr_payslip(osv.osv):
|
|||
\n* If the payslip is under verification, the status is \'Waiting\'. \
|
||||
\n* If the payslip is confirmed then status is set to \'Done\'.\
|
||||
\n* When user cancel payslip the status is \'Rejected\'.'),
|
||||
# 'line_ids': fields.one2many('hr.payslip.line', 'slip_id', 'Payslip Line', required=False, readonly=True, states={'draft': [('readonly', False)]}),
|
||||
'line_ids': one2many_mod2('hr.payslip.line', 'slip_id', 'Payslip Lines', readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'company_id': fields.many2one('res.company', 'Company', required=False, readonly=True, states={'draft': [('readonly', False)]}),
|
||||
'worked_days_line_ids': fields.one2many('hr.payslip.worked_days', 'payslip_id', 'Payslip Worked Days', required=False, readonly=True, states={'draft': [('readonly', False)]}),
|
||||
|
@ -983,19 +979,16 @@ class hr_employee(osv.osv):
|
|||
return res
|
||||
|
||||
def _payslip_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for employee in self.browse(cr, uid, ids, context=context):
|
||||
res[employee.id] = len(employee.payslip_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Payslip = self.pool['hr.payslip']
|
||||
return {
|
||||
employee_id: Payslip.search_count(cr,uid, [('employee_id', '=', employee_id)], context=context)
|
||||
for employee_id in ids
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'slip_ids':fields.one2many('hr.payslip', 'employee_id', 'Payslips', required=False, readonly=True),
|
||||
'total_wage': fields.function(_calculate_total_wage, method=True, type='float', string='Total Basic Salary', digits_compute=dp.get_precision('Payroll'), help="Sum of all current contract's wage of employee."),
|
||||
'payslip_count': fields.function(_payslip_count, type='integer', string='Payslips'),
|
||||
'payslip_ids': fields.one2many('hr.payslip', 'employee_id', 'Payslips'),
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -530,15 +530,14 @@ class hr_job(osv.osv):
|
|||
return res
|
||||
|
||||
def _count_all(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,{'documents_count': 0, 'application_count': 0,}), ids))
|
||||
try:
|
||||
for job in self.browse(cr, uid, ids, context=context):
|
||||
res[job.id] = {'documents_count': len(job.document_ids),
|
||||
'application_count': len(job.applicant_ids),
|
||||
}
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Applicant = self.pool['hr.applicant']
|
||||
return {
|
||||
job_id: {
|
||||
'application_count': Applicant.search_count(cr,uid, [('job_id', '=', job_id)], context=context),
|
||||
'documents_count': len(self._get_attached_docs(cr, uid, [job_id], field_name, arg, context=context)[job_id])
|
||||
}
|
||||
for job_id in ids
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'survey_id': fields.many2one('survey.survey', 'Interview Form', help="Choose an interview form for this job position and you will be able to print/answer this interview from all applicants who apply for this job"),
|
||||
|
|
|
@ -134,15 +134,15 @@ class hr_timesheet_sheet(osv.osv):
|
|||
return hr_employee.attendance_action_change(cr, uid, employee_ids, context=context)
|
||||
|
||||
def _count_all(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,{'timesheet_activity_count': 0, 'attendance_count': 0,}), ids))
|
||||
try:
|
||||
for datas in self.browse(cr, uid, ids, context=context):
|
||||
res[datas.id] = {'timesheet_activity_count': len(datas.timesheet_activity_ids),
|
||||
'attendance_count': len(datas.attendances_ids),
|
||||
}
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Timesheet = self.pool['hr.analytic.timesheet']
|
||||
Attendance = self.pool['hr.attendance']
|
||||
return {
|
||||
sheet_id: {
|
||||
'timesheet_activity_count': Timesheet.search_count(cr,uid, [('sheet_id','=', sheet_id)], context=context),
|
||||
'attendance_count': Attendance.search_count(cr,uid, [('sheed_id', '=', sheet_id)], context=context)
|
||||
}
|
||||
for sheet_id in ids
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Note', size=64, select=1,
|
||||
|
@ -174,7 +174,6 @@ class hr_timesheet_sheet(osv.osv):
|
|||
'account_ids': fields.one2many('hr_timesheet_sheet.sheet.account', 'sheet_id', 'Analytic accounts', readonly=True),
|
||||
'company_id': fields.many2one('res.company', 'Company'),
|
||||
'department_id':fields.many2one('hr.department','Department'),
|
||||
'timesheet_activity_ids': fields.one2many('hr.analytic.timesheet', 'sheet_id', 'Timesheet Activities'),
|
||||
'timesheet_activity_count': fields.function(_count_all, type='integer', string='Timesheet Activities', multi=True),
|
||||
'attendance_count': fields.function(_count_all, type='integer', string="Attendances", multi=True),
|
||||
}
|
||||
|
@ -610,17 +609,14 @@ class hr_employee(osv.osv):
|
|||
_description = 'Employee'
|
||||
|
||||
def _timesheet_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for employee in self.browse(cr, uid, ids, context=context):
|
||||
res[employee.id] = len(employee.timesheet_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Sheet = self.pool['hr_timesheet_sheet.sheet']
|
||||
return {
|
||||
employee_id: Sheet.search_count(cr,uid, [('employee_id', '=', employee_id)], context=context)
|
||||
for employee_id in ids
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'timesheet_ids': fields.one2many('hr_timesheet_sheet.sheet', 'employee_id', 'Timesheets'),
|
||||
'timesheet_count': fields.function(_timesheet_count, type='integer', string='Timsheets'),
|
||||
'timesheet_count': fields.function(_timesheet_count, type='integer', string='Timesheets'),
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -1111,24 +1111,22 @@ class mrp_production_product_line(osv.osv):
|
|||
|
||||
class product_product(osv.osv):
|
||||
_inherit = "product.product"
|
||||
def _bom_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,{'bom_count': 0, 'mo_count': 0, 'bom_strct':0}), ids))
|
||||
try:
|
||||
for bom in self.browse(cr, uid, ids, context=context):
|
||||
res[bom.id] = {
|
||||
'bom_count': len(bom.bom_ids),
|
||||
'mo_count': len(bom.mo_ids),
|
||||
'bom_strct':len(bom.bom_ids),
|
||||
}
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
def _bom_orders_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
Bom = self.pool('mrp.bom')
|
||||
Production = self.pool('mrp.production')
|
||||
return {
|
||||
product_id: {
|
||||
'bom_count': Bom.search_count(cr, uid, [('product_id', '=', product_id), ('bom_id', '=', False)], context=context),
|
||||
'mo_count': Production.search_count(cr,uid, [('product_id', '=', product_id)], context=context),
|
||||
'bom_strct': Bom.search_count(cr, uid, [('product_id', '=', product_id), ('bom_id', '=', False)], context=context),
|
||||
}
|
||||
for product_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'bom_ids': fields.one2many('mrp.bom', 'product_id', 'Bill of Materials'),
|
||||
'mo_ids': fields.one2many('mrp.production', 'product_id', 'Manufacturing Orders'),
|
||||
'bom_count': fields.function(_bom_count, string='# Bill of Material', type='integer', multi="bom_count"),
|
||||
'bom_strct': fields.function(_bom_count, string='# Bill of Material Structure', type='integer', multi="bom_count"),
|
||||
'mo_count': fields.function(_bom_count, string='# Manufacturing Orders', type='integer', multi="bom_count"),
|
||||
'bom_count': fields.function(_bom_orders_count, string='# Bill of Material', type='integer', multi="_bom_order_count"),
|
||||
'bom_strct': fields.function(_bom_orders_count, string='# Bill of Material Structure', type='integer', multi="_bom_order_count"),
|
||||
'mo_count': fields.function(_bom_orders_count, string='# Manufacturing Orders', type='integer', multi="_bom_order_count"),
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -615,15 +615,12 @@ class product_template(osv.osv):
|
|||
class product_product(osv.osv):
|
||||
_inherit="product.product"
|
||||
def _orderpoint_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for orderpoint in self.browse(cr, uid, ids, context=context):
|
||||
res[orderpoint.id] = len(orderpoint.orderpoint_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
OrderPoints = self.pool('stock.warehouse.orderpoint')
|
||||
return {
|
||||
product_id: OrderPoints.search_count(cr, uid, [('product_id', '=', product_id)], context=context)
|
||||
for product_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'orderpoint_ids': fields.one2many('stock.warehouse.orderpoint', 'product_id', 'Minimum Stock Rules'),
|
||||
'orderpoint_count': fields.function(_orderpoint_count, string='# Orderpoints', type='integer'),
|
||||
}
|
||||
|
||||
|
|
|
@ -23,13 +23,11 @@ from openerp.osv import fields,osv
|
|||
|
||||
class res_partner(osv.osv):
|
||||
def _task_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for partner in self.browse(cr, uid, ids, context):
|
||||
res[partner.id] = len(partner.task_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Task = self.pool['project.task']
|
||||
return {
|
||||
partner_id: Task.search_count(cr,uid, [('partner_id', '=', partner_id)], context=context)
|
||||
for partner_id in ids
|
||||
}
|
||||
|
||||
""" Inherits partner and adds Tasks information in the partner form """
|
||||
_inherit = 'res.partner'
|
||||
|
@ -46,6 +44,4 @@ class res_partner(osv.osv):
|
|||
return super(res_partner, self).copy(
|
||||
cr, uid, record_id, default=default, context=context)
|
||||
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -490,10 +490,11 @@ class project(osv.Model):
|
|||
return [('project.task', "Tasks"), ("project.issue", "Issues")]
|
||||
|
||||
def _issue_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res={}
|
||||
for issues in self.browse(cr, uid, ids, context):
|
||||
res[issues.id] = len(issues.issue_ids)
|
||||
return res
|
||||
Issue = self.pool['project.issue']
|
||||
return {
|
||||
project_id: Issue.search_count(cr,uid, [('project_id', '=', project_id), ('stage_id.fold', '=', False)], context=context)
|
||||
for project_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'project_escalation_id': fields.many2one('project.project', 'Project Escalation',
|
||||
help='If any issue is escalated from the current Project, it will be listed under the project selected here.',
|
||||
|
@ -570,18 +571,15 @@ class project_project(osv.Model):
|
|||
|
||||
class res_partner(osv.osv):
|
||||
def _issue_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for partner in self.browse(cr, uid, ids, context=context):
|
||||
res[partner.id] = len(partner.issue_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Issue = self.pool['project.issue']
|
||||
return {
|
||||
partner_id: Issue.search_count(cr,uid, [('partner_id', '=', partner_id)])
|
||||
for partner_id in ids
|
||||
}
|
||||
|
||||
""" Inherits partner and adds Issue information in the partner form """
|
||||
_inherit = 'res.partner'
|
||||
_columns = {
|
||||
'issue_ids': fields.one2many('project.issue', 'partner_id', 'Issues'),
|
||||
'issue_count': fields.function(_issue_count, string='# Issues', type='integer'),
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -25,22 +25,16 @@ class res_partner(osv.osv):
|
|||
_name = 'res.partner'
|
||||
_inherit = 'res.partner'
|
||||
|
||||
def _purchase_order_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,{'purchase_order_count': 0, 'supplier_invoice_count': 0}), ids))
|
||||
invoice_ids = self.pool.get('account.invoice').search(cr,uid, [('type', '=', 'in_invoice'), ('partner_id', '=', ids[0])])
|
||||
for partner in self.browse(cr, uid, ids, context=context):
|
||||
res[partner.id] = {
|
||||
'purchase_order_count': len(partner.purchase_order_ids),
|
||||
'supplier_invoice_count': len(invoice_ids),
|
||||
}
|
||||
return res
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
if default is None:
|
||||
default = {}
|
||||
|
||||
default.update({'purchase_order_ids': []})
|
||||
|
||||
return super(res_partner, self).copy(cr, uid, id, default=default, context=context)
|
||||
def _purchase_invoice_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
PurchaseOrder = self.pool['purchase.order']
|
||||
Invoice = self.pool['account.invoice']
|
||||
return {
|
||||
partner_id: {
|
||||
'purchase_order_count': PurchaseOrder.search_count(cr,uid, [('partner_id', '=', partner_id)], context=context),
|
||||
'supplier_invoice_count': Invoice.search_count(cr,uid, [('partner_id', '=', partner_id), ('type','=','in_invoice')], context=context)
|
||||
}
|
||||
for partner_id in ids
|
||||
}
|
||||
|
||||
def _commercial_fields(self, cr, uid, context=None):
|
||||
return super(res_partner, self)._commercial_fields(cr, uid, context=context) + ['property_product_pricelist_purchase']
|
||||
|
@ -52,13 +46,9 @@ class res_partner(osv.osv):
|
|||
domain=[('type','=','purchase')],
|
||||
string="Purchase Pricelist",
|
||||
help="This pricelist will be used, instead of the default one, for purchases from the current partner"),
|
||||
'purchase_order_count': fields.function(_purchase_order_count, string='# of Purchase Order', type='integer', multi="count"),
|
||||
'purchase_order_ids': fields.one2many('purchase.order','partner_id','Purchase Order'),
|
||||
'invoice_ids': fields.one2many('account.invoice','partner_id','Supplier Invoices'),
|
||||
'supplier_invoice_count': fields.function(_purchase_order_count, string='# Supplier Invoices', type='integer', multi="count"),
|
||||
'purchase_order_count': fields.function(_purchase_invoice_count, string='# of Purchase Order', type='integer', multi="count"),
|
||||
'supplier_invoice_count': fields.function(_purchase_invoice_count, string='# Supplier Invoices', type='integer', multi="count"),
|
||||
}
|
||||
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -148,15 +148,13 @@ class purchase_order(osv.osv):
|
|||
return res and res[0] or False
|
||||
|
||||
def _count_all(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,{'shipment_count': 0, 'invoice_count': 0,}), ids))
|
||||
try:
|
||||
for data in self.browse(cr, uid, ids, context=context):
|
||||
res[data.id] = {'shipment_count': len(data.picking_ids),
|
||||
'invoice_count': len(data.invoice_ids),
|
||||
}
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
return {
|
||||
purchase.id: {
|
||||
'shipment_count': len(purchase.picking_ids),
|
||||
'invoice_count': len(purchase.invoice_ids),
|
||||
}
|
||||
for purchase in self.browse(cr, uid, ids, context=context)
|
||||
}
|
||||
|
||||
STATE_SELECTION = [
|
||||
('draft', 'Draft PO'),
|
||||
|
@ -1296,15 +1294,13 @@ class product_product(osv.Model):
|
|||
_inherit = 'product.product'
|
||||
|
||||
def _purchase_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for purchase in self.browse(cr, uid, ids, context=context):
|
||||
res[purchase.id] = len(purchase.purchase_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Purchase = self.pool['purchase.order']
|
||||
return {
|
||||
product_id: Purchase.search_count(cr,uid, [('order_line.product_id', '=', product_id)], context=context)
|
||||
for product_id in ids
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'purchase_ids': fields.one2many('purchase.order', 'product_id', 'Purchases'),
|
||||
'purchase_count': fields.function(_purchase_count, string='# Purchases', type='integer'),
|
||||
}
|
||||
|
||||
|
|
|
@ -1027,15 +1027,12 @@ class account_invoice(osv.Model):
|
|||
class product_product(osv.Model):
|
||||
_inherit = 'product.product'
|
||||
def _sales_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for sale in self.browse(cr, uid, ids, context=context):
|
||||
res[sale.id] = len(sale.sales_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
SaleOrderLine = self.pool['sale.order.line']
|
||||
return {
|
||||
product_id: SaleOrderLine.search_count(cr,uid, [('product_id', '=', product_id)], context=context)
|
||||
for product_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'sales_ids': fields.one2many('sale.order.line', 'product_id', 'Sales '),
|
||||
'sales_count': fields.function(_sales_count, string='# Sales', type='integer'),
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -353,13 +353,11 @@ class product_product(osv.osv):
|
|||
res[id][f] = stock.get(id, 0.0)
|
||||
return res
|
||||
def _move_count(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x,0), ids))
|
||||
try:
|
||||
for move in self.browse(cr, uid, ids, context=context):
|
||||
res[move.id] = len(move.move_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
Move = self.pool['stock.move']
|
||||
return {
|
||||
product_id: Move.search_count(cr, uid, [('product_id', '=', product_id)], context=context)
|
||||
for product_id in ids
|
||||
}
|
||||
_columns = {
|
||||
'reception_count': fields.function(_stock_move_count, string="Reception", type='integer', multi='pickings'),
|
||||
'delivery_count': fields.function(_stock_move_count, string="Delivery", type='integer', multi='pickings'),
|
||||
|
@ -420,7 +418,6 @@ class product_product(osv.osv):
|
|||
help="If real-time valuation is enabled for a product, the system will automatically write journal entries corresponding to stock moves." \
|
||||
"The inventory variation account set on the product category will represent the current inventory value, and the stock input and stock output account will hold the counterpart moves for incoming and outgoing products."
|
||||
, required=True),
|
||||
'move_ids': fields.one2many('stock.move', 'product_id', 'Moves'),
|
||||
'move_count': fields.function(_move_count, string='# Moves', type='integer'),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue