Skip to Content
Menu
This question has been flagged
3485 Zobrazenia


 

from openerp import api, fields, models

import date

class fido_bagging(models.Model):

_name = "fido.bagger"

name = fields.Many2one('hr.employee',string='Bagger', size=32, required=True)

fido_date = fields.Datetime(string='Date')

x_quantity = fields.Integer(string="No of Bags")

class fido_bagging_inherit(models.Model):

_inherit = "hr.employee"

dummy_object = fields.One2many('fido.bagger', 'name', size=32)

@api.one

def compute_bag_total(self):

cursor = self._cr

user = self._uid

for employees in self:

today = datetime.datetime.today()

start_date = str(today.replace(day=1).strftime('%m/%d/%Y'))

next_month = today.replace(day=28) + datetime.timedelta(days=4)

end_date = str(next_month - datetime.timedelta(days=next_month.day-1))

print ("########START DATE", start_date)

print ("######## END DATE", end_date)

#look up the bagging records

fido_bagger_obj = self.pool.get('fido.bagger')

bagger_ids = fido_bagger_obj.search(cursor, user,[('fido_date','>=',start_date),('fido_date','<=',end_date),('name','=',employees.name)])

# bagger_ids = fido_bagger_obj.search(cursor, user, [('name','=',employees.id)])

total = 0.0

for fido_bagger in fido_bagger_obj.browse(cursor, user, bagger_ids):

total += fido_bagger.x_quantity

employees.mtd_bag = total

mtd_bag = fields.Float(compute='compute_bag_total',string="Month Bag")

 

 im trying to get the total amount of bags sold in each month for all the employees that are baggers

Avatar
Zrušiť

I'm going to watch this subject, need something similar to this but in products :)

Autor

i solved it eventually. i changed my strftime format to (%Y-%m-%d)

Related Posts Replies Zobrazenia Aktivita
3
jún 25
1164
1
jan 25
18024
1
jan 20
3992
1
dec 19
6441
1
dec 19
17334