Move code at the right place !
This commit is contained in:
@@ -57,48 +57,6 @@ class AccountInvoice(models.Model):
|
||||
# return res
|
||||
|
||||
|
||||
# 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.invoice_line_ids, 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 line in ldict['lines']:
|
||||
res2.append({'line': line})
|
||||
if 'subtotal' in ldict:
|
||||
res2.append({'subtotal': ldict['subtotal']})
|
||||
# res2:
|
||||
# [
|
||||
# {'categ': categ(1)},
|
||||
# {'line': invoice_line(2)},
|
||||
# {'line': invoice_line(3)},
|
||||
# {'subtotal': 8932.23},
|
||||
# ]
|
||||
return res2
|
||||
|
||||
|
||||
class AccountInvoiceLine(models.Model):
|
||||
_inherit = 'account.invoice.line'
|
||||
|
||||
|
||||
@@ -75,9 +75,56 @@ class SaleOrder(models.Model):
|
||||
# ]
|
||||
return res2
|
||||
|
||||
|
||||
class ProcurementGroup(models.Model):
|
||||
_inherit = 'procurement.group'
|
||||
|
||||
sale_ids = fields.One2many(
|
||||
'sale.order', 'procurement_group_id', string='Sale Orders',
|
||||
readonly=True)
|
||||
|
||||
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = 'account.invoice'
|
||||
|
||||
# for report (located in sale_usability and not account_usability
|
||||
# because it uses layout categ defined in sale
|
||||
@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.invoice_line_ids, 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 line in ldict['lines']:
|
||||
res2.append({'line': line})
|
||||
if 'subtotal' in ldict:
|
||||
res2.append({'subtotal': ldict['subtotal']})
|
||||
# res2:
|
||||
# [
|
||||
# {'categ': categ(1)},
|
||||
# {'line': invoice_line(2)},
|
||||
# {'line': invoice_line(3)},
|
||||
# {'subtotal': 8932.23},
|
||||
# ]
|
||||
return res2
|
||||
|
||||
Reference in New Issue
Block a user