Skip to content

Commit

Permalink
Merge 912231e into 6494c9f
Browse files Browse the repository at this point in the history
  • Loading branch information
antespi committed Apr 14, 2016
2 parents 6494c9f + 912231e commit dec3590
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 117 deletions.
1 change: 1 addition & 0 deletions sale_service_project/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Contributors
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Carlos Dauden <carlos@incaser.es>
* Sergio Teruel <sergio@incaser.es>
* Antonio Espinosa <antonioea@antiun.com>

Maintainer
----------
Expand Down
4 changes: 3 additions & 1 deletion sale_service_project/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería S.L. - Sergio Teruel
# © 2015 Antiun Ingeniería S.L. - Carlos Dauden
# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
'name': "Sale Service Project",
'category': 'Sales',
'version': '8.0.1.0.0',
'version': '8.0.1.1.0',
'depends': [
'project_task_materials',
'sale_service',
Expand All @@ -21,6 +22,7 @@
'views/sale_view.xml',
'views/account_invoice_view.xml',
'views/project_view.xml',
'views/report_common.xml',
'views/report_saleorder.xml',
'views/report_invoice.xml',
'wizard/product_price_service_view.xml',
Expand Down
21 changes: 20 additions & 1 deletion sale_service_project/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# © 2015 Antiun Ingeniería S.L. - Carlos Dauden
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import fields, models
from openerp import fields, models, api
from openerp.report.report_sxw import rml_parse


class AccountInvoice(models.Model):
Expand All @@ -29,3 +30,21 @@ class AccountInvoiceLine(models.Model):
comodel_name='project.task.materials',
column1='invoice_line_id', column2='material_line_id',
readonly=True, string='Materials')


class SaleOrderReport(models.AbstractModel):
_name = 'report.account.report_invoice'

@api.multi
def render_html(self, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('account.report_invoice')
docargs = {
'doc_ids': self._ids,
'doc_model': report.model,
'docs': self,
'formatLang':rml_parse(
self.env.cr, self.env.uid, 'account.report_invoice'
).formatLang,
}
return report_obj.render('account.report_invoice', docargs)
4 changes: 4 additions & 0 deletions sale_service_project/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ def action_compute_price(self):

class ProductTaskWork(models.Model):
_name = 'product.task.work'
_order = 'sequence'

product_id = fields.Many2one(
comodel_name='product.template', string='Product', ondelete='restrict')
name = fields.Char(string='Name')
hours = fields.Float(
string='Hours',
digits_compute=dp.get_precision('Product Unit of Measure'))
sequence = fields.Integer()


class ProductProduct(models.Model):
Expand All @@ -63,6 +65,7 @@ def action_compute_price(self):

class ProductTaskMaterials(models.Model):
_name = 'product.task.materials'
_order = 'sequence'

product_id = fields.Many2one(
comodel_name='product.template', string='Product', ondelete='restrict')
Expand All @@ -71,3 +74,4 @@ class ProductTaskMaterials(models.Model):
quantity = fields.Float(
string='Quantity',
digits_compute=dp.get_precision('Product Unit of Measure'))
sequence = fields.Integer()
59 changes: 44 additions & 15 deletions sale_service_project/models/sale.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
# © 2015 Antiun Ingeniería S.L. - Sergio Teruel
# © 2015 Antiun Ingeniería S.L. - Carlos Dauden
# © 2016 Antiun Ingenieria S.L. - Antonio Espinosa
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, fields, api
from openerp.addons.decimal_precision import decimal_precision as dp
from openerp.report.report_sxw import rml_parse


class SaleOrder(models.Model):
Expand Down Expand Up @@ -125,38 +127,65 @@ def product_id_change(
return res

@api.multi
@api.onchange(
'task_work_product_id', 'task_work_ids', 'task_materials_ids')
@api.onchange('task_work_product_id', 'compute_price',
'task_work_ids', 'task_materials_ids')
def _onchange_task_work_product_id(self):
if self.compute_price and self.task_work_product_id:
total_hours = sum(self.mapped('task_work_ids.hours') or [0.0])
total_price_hours = (
self.task_work_product_id.list_price * total_hours)
materials = self.mapped('task_materials_ids')
total_price_materials = sum(
[m.quantity * m.product_id.lst_price for m in materials])
total_price = total_price_hours + total_price_materials
self.price_unit = total_price
for line in self:
if line.compute_price and line.task_work_product_id:
pricelist_id = line.order_id.pricelist_id.id
partner_id = line.order_id.partner_id.id
total_hours = sum(line.mapped('task_work_ids.hours') or [0.0])
price_hours = line.order_id.pricelist_id.price_get(
line.task_work_product_id.id, total_hours,
partner_id)[pricelist_id]
total_price_hours = (price_hours * total_hours)
total_price_materials = 0.0
for material in line.mapped('task_materials_ids'):
material_price = line.order_id.pricelist_id.price_get(
material.product_id.id, material.quantity,
partner_id)[pricelist_id]
total_price_materials += (
material.quantity * material_price)
line.price_unit = total_price_hours + total_price_materials


class SaleOrderLineTaskWork(models.Model):
_name = 'sale.order.line.task.work'
_order = 'sequence'

order_line_id = fields.Many2one(
comodel_name='sale.order.line', string='Order Line')
name = fields.Char(string='Name')
hours = fields.Float(
string='Hours',
digits_compute=dp.get_precision('Product Unit of Measure'))
string='Hours', digits=dp.get_precision('Product UoS'))
sequence = fields.Integer()


class SaleOrderLineTaskMaterials(models.Model):
_name = 'sale.order.line.task.materials'
_order = 'sequence'

order_line_id = fields.Many2one(
comodel_name='sale.order.line', string='Order Line')
product_id = fields.Many2one(
comodel_name='product.product', string='Material')
quantity = fields.Float(
string='Quantity',
digits_compute=dp.get_precision('Product Unit of Measure'))
string='Quantity', digits=dp.get_precision('Product UoS'))
sequence = fields.Integer()


class SaleOrderReport(models.AbstractModel):
_name = 'report.sale.report_saleorder'

@api.multi
def render_html(self, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('sale.report_saleorder')
docargs = {
'doc_ids': self._ids,
'doc_model': report.model,
'docs': self,
'formatLang': rml_parse(
self.env.cr, self.env.uid, 'sale.report_saleorder').formatLang,
}
return report_obj.render('sale.report_saleorder', docargs)
28 changes: 28 additions & 0 deletions sale_service_project/static/src/css/report.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.table > tbody > .works_title > td,
.table > tbody > .works_line > td,
.table > tbody > .materials_title > td,
.table > tbody > .materials_line > td {
border: 0;
}

.table > tbody > .works_title > .works_lbl,
.table > tbody > .materials_title > .materials_lbl {
padding-left: 15px;
font-style: italic;
text-decoration: underline;
}

.table > tbody > .works_line > .works_line_name,
.table > tbody > .materials_line > .materials_line_name {
padding-left: 25px;
}

.works_line_hours, .works_line_price,
.materials_line_qty, .materials_line_price {
text-align: right;
}

.table > tbody > .invoice_works_line > td,
.table > tbody > .invoice_materials_line > td {
border: 0;
}
17 changes: 17 additions & 0 deletions sale_service_project/views/report_common.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- © 2016 Antiun Ingenieria S.L. - Antonio Espinosa
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp>
<data>

<template id="minimal_layout"
inherit_id="report.minimal_layout"
name="Sale service project report CSS">
<xpath expr="//head" position="inside">
<link rel="stylesheet"
href="/sale_service_project/static/src/css/report.css"/>
</xpath>
</template>

</data>
</openerp>

0 comments on commit dec3590

Please sign in to comment.