コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3474 ビュー


 

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

アバター
破棄

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

著作者

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

関連投稿 返信 ビュー 活動
3
6月 25
1163
1
1月 25
18023
1
1月 20
3991
1
12月 19
6440
1
12月 19
17333