Update for sale_report_py3o
Code cleanup
This commit is contained in:
@@ -25,7 +25,7 @@ class SaleOrder(models.Model):
|
|||||||
has_discount = fields.Boolean(
|
has_discount = fields.Boolean(
|
||||||
compute='_compute_has_discount', readonly=True)
|
compute='_compute_has_discount', readonly=True)
|
||||||
|
|
||||||
@api.multi
|
@api.depends('order_line.discount')
|
||||||
def _compute_has_discount(self):
|
def _compute_has_discount(self):
|
||||||
prec = self.env['decimal.precision'].precision_get('Discount')
|
prec = self.env['decimal.precision'].precision_get('Discount')
|
||||||
for order in self:
|
for order in self:
|
||||||
@@ -37,38 +37,30 @@ class SaleOrder(models.Model):
|
|||||||
order.has_discount = has_discount
|
order.has_discount = has_discount
|
||||||
|
|
||||||
# for report
|
# for report
|
||||||
@api.multi
|
|
||||||
def py3o_lines_layout(self):
|
def py3o_lines_layout(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
res1 = OrderedDict()
|
res = []
|
||||||
# {categ(6): {'lines': [l1, l2], 'subtotal': 23.32}}
|
has_sections = False
|
||||||
|
subtotal = 0.0
|
||||||
for line in self.order_line:
|
for line in self.order_line:
|
||||||
categ = line.layout_category_id
|
if line.display_type == 'line_section':
|
||||||
if categ in res1:
|
# insert line
|
||||||
res1[categ]['lines'].append(line)
|
if has_sections:
|
||||||
res1[categ]['subtotal'] += line.price_subtotal
|
res.append({'subtotal': subtotal})
|
||||||
|
subtotal = 0.0 # reset counter
|
||||||
|
has_sections = True
|
||||||
else:
|
else:
|
||||||
res1[categ] = {
|
if not line.display_type:
|
||||||
'lines': [line],
|
subtotal += line.price_subtotal
|
||||||
'subtotal': line.price_subtotal}
|
res.append({'line': line})
|
||||||
|
if has_sections: # insert last subtotal line
|
||||||
res2 = []
|
res.append({'subtotal': subtotal})
|
||||||
if len(res1) == 1 and not res1.keys()[0]:
|
# res:
|
||||||
# No category at all
|
|
||||||
for line in res1.values()[0]['lines']:
|
|
||||||
res2.append({'line': line})
|
|
||||||
else:
|
|
||||||
for categ, ldict in res1.iteritems():
|
|
||||||
res2.append({'categ': categ})
|
|
||||||
for line in ldict['lines']:
|
|
||||||
res2.append({'line': line})
|
|
||||||
if categ.subtotal:
|
|
||||||
res2.append({'subtotal': ldict['subtotal']})
|
|
||||||
# res2:
|
|
||||||
# [
|
# [
|
||||||
# {'categ': categ(1)},
|
# {'line': sale_order_line(1) with display_type=='line_section'},
|
||||||
# {'line': sale_order_line(2)},
|
# {'line': sale_order_line(2) without display_type},
|
||||||
# {'line': sale_order_line(3)},
|
# {'line': sale_order_line(3) without display_type},
|
||||||
|
# {'line': sale_order_line(4) with display_type=='line_note'},
|
||||||
# {'subtotal': 8932.23},
|
# {'subtotal': 8932.23},
|
||||||
# ]
|
# ]
|
||||||
return res2
|
return res
|
||||||
|
|||||||
@@ -76,15 +76,15 @@ class StockMove(models.Model):
|
|||||||
in it'''
|
in it'''
|
||||||
res = []
|
res = []
|
||||||
for line in self:
|
for line in self:
|
||||||
name = line.location_id.name + ' > ' + line.location_dest_id.name
|
name = '%s > %s' % (line.location_id.name, line.location_dest_id.name)
|
||||||
if line.product_id.code:
|
if line.product_id.code:
|
||||||
name = line.product_id.code + ': ' + name
|
name = '%s: %s' % (line.product_id.code, name)
|
||||||
if line.picking_id.origin:
|
if line.picking_id.origin:
|
||||||
name = line.picking_id.origin + ' ' + name
|
name = '%s %s' % (line.picking_id.origin, name)
|
||||||
if line.partner_id:
|
if line.partner_id:
|
||||||
name = line.partner_id.name + ' ' + name
|
name = '%s %s' % (line.partner_id.name, name)
|
||||||
if line.date_expected:
|
if line.date_expected:
|
||||||
name = name + ' ' + line.date_expected
|
name = '%s %s' % (name, line.date_expected)
|
||||||
res.append((line.id, name))
|
res.append((line.id, name))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user