Add has_discount on SO + method for py3o report
This commit is contained in:
@@ -2,7 +2,9 @@
|
|||||||
# Copyright (C) 2015 Akretion (http://www.akretion.com)
|
# Copyright (C) 2015 Akretion (http://www.akretion.com)
|
||||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
|
||||||
from odoo import models, fields
|
from odoo import models, fields, api
|
||||||
|
from odoo.tools import float_is_zero
|
||||||
|
from itertools import groupby
|
||||||
|
|
||||||
|
|
||||||
class SaleOrder(models.Model):
|
class SaleOrder(models.Model):
|
||||||
@@ -17,7 +19,60 @@ class SaleOrder(models.Model):
|
|||||||
pricelist_id = fields.Many2one(track_visibility='onchange')
|
pricelist_id = fields.Many2one(track_visibility='onchange')
|
||||||
payment_term_id = fields.Many2one(track_visibility='onchange')
|
payment_term_id = fields.Many2one(track_visibility='onchange')
|
||||||
fiscal_position_id = fields.Many2one(track_visibility='onchange')
|
fiscal_position_id = fields.Many2one(track_visibility='onchange')
|
||||||
|
# for reports
|
||||||
|
has_discount = fields.Boolean(
|
||||||
|
compute='_compute_has_discount', readonly=True)
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def _compute_has_discount(self):
|
||||||
|
prec = self.env['decimal.precision'].precision_get('Discount')
|
||||||
|
for order in self:
|
||||||
|
has_discount = False
|
||||||
|
for line in order.order_line:
|
||||||
|
if not float_is_zero(line.discount, precision_digits=prec):
|
||||||
|
has_discount = True
|
||||||
|
break
|
||||||
|
order.has_discount = has_discount
|
||||||
|
|
||||||
|
# for report
|
||||||
|
@api.multi
|
||||||
|
def py3o_lines_layout(self):
|
||||||
|
self.ensure_one()
|
||||||
|
res1 = []
|
||||||
|
# [
|
||||||
|
# {'categ': categ(6), 'lines': [l1, l2], 'subtotal': 23.32},
|
||||||
|
# {'categ': categ(1), 'lines': [l3, l4, l5], 'subtotal': 12.42},
|
||||||
|
# ]
|
||||||
|
for categ, lines in groupby(self.order_line, lambda l: l.layout_category_id):
|
||||||
|
entry = {'lines': [], 'categ': categ}
|
||||||
|
if categ.subtotal:
|
||||||
|
entry['subtotal'] = 0.0
|
||||||
|
for line in lines:
|
||||||
|
entry['lines'].append(line)
|
||||||
|
if 'subtotal' in entry:
|
||||||
|
entry['subtotal'] += line.price_subtotal
|
||||||
|
res1.append(entry)
|
||||||
|
res2 = []
|
||||||
|
if len(res1) == 1 and not res1[0]['categ']:
|
||||||
|
# No category at all
|
||||||
|
for l in res1[0]['lines']:
|
||||||
|
res2.append({'line': l})
|
||||||
|
else:
|
||||||
|
# TODO : gérer qd il n'y a pas de categ
|
||||||
|
for ldict in res1:
|
||||||
|
res2.append({'categ': ldict['categ']})
|
||||||
|
for soline in ldict['lines']:
|
||||||
|
res2.append({'line': soline})
|
||||||
|
if 'subtotal' in ldict:
|
||||||
|
res2.append({'subtotal': ldict['subtotal']})
|
||||||
|
# res2:
|
||||||
|
# [
|
||||||
|
# {'categ': categ(1)},
|
||||||
|
# {'line': sale_order_line(2)},
|
||||||
|
# {'line': sale_order_line(3)},
|
||||||
|
# {'subtotal': 8932.23},
|
||||||
|
# ]
|
||||||
|
return res2
|
||||||
|
|
||||||
class ProcurementGroup(models.Model):
|
class ProcurementGroup(models.Model):
|
||||||
_inherit = 'procurement.group'
|
_inherit = 'procurement.group'
|
||||||
|
|||||||
Reference in New Issue
Block a user