Backport intrastat_product_type from 8 to 7

This commit is contained in:
Alexis de Lattre
2016-05-12 17:38:04 +02:00
parent 38dd25f471
commit 158648e604
5 changed files with 129 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import intrastat_product_type

View File

@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Intrastat Product Type module for Odoo
# Copyright (C) 2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Intrastat Product Type',
'version': '0.1',
'category': 'Accounting & Finance',
'license': 'AGPL-3',
'summary': 'Adds a special field Intrastat Type on Products',
'description': """
Intrastat Product Type
======================
This module is designed for a very special usage scenario. Some companies want to handle the delivery of services the same way as they handle the delivery of goods ; they want to show the services in the delivery note, etc. So, those companies configure the services with Type = *Consumable*. This works well to have the services on the outgoing pickings, but it is a problem for the intrastat declarations.
This module adds a field *Intrastat Type* on the Product Form with 2 possible options: *Product* or *Service*. The intrastat declaration will use this field instead of the native *Type* field.
This module has been written by Alexis de Lattre from Akretion <alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['l10n_fr_intrastat_product', 'l10n_fr_intrastat_service'],
'data': ['product_view.xml'],
'installable': True,
}

View File

@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# © 2016 Akretion (http://www.akretion.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# @author Alexis de Lattre <alexis.delattre@akretion.com>
from openerp.osv import orm, fields
class ProductTemplate(orm.Model):
_inherit = 'product.template'
_columns = {
'intrastat_type': fields.selection([
('product', 'Product'),
('service', 'Service'),
], string='Intrastat Type', required=True,
help="Type of product used for the intrastat declarations. "
"For example, you can configure a product with "
"'Product Type' = 'Consumable' and 'Intrastat Type' = 'Service'.")
}
_defaults = {
'intrastat_type': 'product',
}
class ReportIntrastatService(orm.Model):
_inherit = "report.intrastat.service"
def _is_service(self, cr, uid, invoice_line, context=None):
if invoice_line.product_id.intrastat_type == 'service':
return True
else:
return False
class ReportIntrastatProduct(orm.Model):
_inherit = 'report.intrastat.product'
def _is_product(self, cr, uid, invoice_line, context=None):
if (
invoice_line.product_id and
invoice_line.product_id.intrastat_type == 'product'):
return True
else:
return False

View File

@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# POST-INIT-HOOK doesn't work in v7 (only v8 and above)
# So the SQL needs to be executed manually
def set_intrastat_type_on_products(cr, pool):
cr.execute(
"UPDATE product_template SET intrastat_type='service' "
"WHERE type='service'")
return

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="product_normal_form_view" model="ir.ui.view">
<field name="name">intrastat_product_type.product.product.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<field name="type" position="after">
<field name="intrastat_type"/>
</field>
</field>
</record>
</data>
</openerp>