Skip to content

Commit

Permalink
[9.0][NEW][WIP] product_supplierinfo_revision: New module
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdauden committed Mar 13, 2017
1 parent 21422b2 commit 7f4d0ed
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 0 deletions.
60 changes: 60 additions & 0 deletions product_supplierinfo_revision/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=============================
Product Supplierinfo Revision
=============================

This module allow create revisions of supplier info prices.


Usage
=====

To use this module:

#. Go to ...


.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/135/9.0


Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/product-attribute/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Carlos Dauden <carlos.dauden@tecnativa.com>


Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
4 changes: 4 additions & 0 deletions product_supplierinfo_revision/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-

from . import models
from . import wizards
21 changes: 21 additions & 0 deletions product_supplierinfo_revision/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Product Supplierinfo Revision",
"summary": "Customizations for Licores Reyes",
"version": "9.0.1.0.0",
"category": "Product",
"website": "http://www.tecnativa.com",
"author": "Tecnativa S.L.",
"license": "AGPL-3",
"installable": True,
"depends": [
"product",
],
"data": [
"views/product_supplierinfo_view.xml",
"wizards/supplierinfo_duplicate_wizard_view.xml",
],
}
19 changes: 19 additions & 0 deletions product_supplierinfo_revision/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_supplierinfo_revision
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-19 14:23+0100\n"
"PO-Revision-Date: 2017-01-19 14:38+0100\n"
"Last-Translator: Carlos Dauden <carlos.dauden@tecnativa.com>\n"
"Language-Team: sergio.teruel@tecnativa.com\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 1.8.7.1\n"
"X-Poedit-SourceCharset: UTF-8\n"
3 changes: 3 additions & 0 deletions product_supplierinfo_revision/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import product_supplierinfo
32 changes: 32 additions & 0 deletions product_supplierinfo_revision/models/product_supplierinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class ProductSupplierinfo(models.Model):
_inherit = 'product.supplierinfo'

previous_info_id = fields.Many2one(
comodel_name='product.supplierinfo',
string='Previous info',
help='Relation with previous info when duplicate line',
)
previous_price = fields.Float(related='previous_info_id.price')
variation_percent = fields.Float(
compute='_compute_variation_percent',
store=True,
digits=dp.get_precision('Product Price'),
string='Variation %',
)

@api.multi
@api.depends('price', 'previous_info_id.price')
def _compute_variation_percent(self):
for line in self:
if not (line.price and line.previous_price):
continue
line.variation_percent = (
(line.price / line.previous_price - 1) * 100)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions product_supplierinfo_revision/views/product_supplierinfo_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!--<record id="product_supplierinfo_form_view" model="ir.ui.view">-->
<!--<field name="name">product.supplierinfo.form.view.variation</field>-->
<!--<field name="model">product.supplierinfo</field>-->
<!--<field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>-->
<!--<field name="arch" type="xml">-->
<!--<xpath expr="//field[@name='price']/.." position="after">-->
<!--<label for="variation_percent"/>-->
<!--<div>-->
<!--<field name="variation_percent" class="oe_inline"/>-->
<!--</div>-->
<!--<label for="previous_price"/>-->
<!--<div>-->
<!--<field name="previous_price" class="oe_inline"/>-->
<!--</div>-->
<!--</xpath>-->
<!--</field>-->
<!--</record>-->

<record id="product_supplierinfo_tree_view" model="ir.ui.view">
<field name="name">product.supplierinfo.tree.view.variation</field>
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>
<field name="arch" type="xml">
<field name="price" position="after">
<field name="variation_percent"/>
</field>
</field>
</record>

</odoo>
3 changes: 3 additions & 0 deletions product_supplierinfo_revision/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import supplierinfo_duplicate_wizard
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# © 2017 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from dateutil.relativedelta import relativedelta

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


class ProductSupplierInfoDuplicateWizard(models.TransientModel):
_name = 'product.supplierinfo.duplicate.wizard'

date_start = fields.Date(required=True)
date_end = fields.Date()
variation_percent = fields.Float(
digits=dp.get_precision('Product Price'),
string='Variation %',
)

@api.multi
def action_apply(self):
Supplierinfo = self.env['product.supplierinfo']
supplierinfo_news = Supplierinfo
for item in Supplierinfo.browse(self.env.context['active_ids']):
supplierinfo_news |= item.copy({
'date_start': self.date_start,
'date_end': self.date_end,
'previous_info_id': item.id,
'price': item.price * (1.0 + self.variation_percent / 100.0),
})
item.date_end = (fields.Date.from_string(self.date_start) -
relativedelta(days=1))

action = self.env.ref(
'product.product_supplierinfo_type_action').read()[0]
if len(supplierinfo_news) > 0:
action['domain'] = [('id', 'in', supplierinfo_news.ids)]
else:
action = {'type': 'ir.actions.act_window_close'}
return action
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="supplierinfo_duplicate_wizard_view" model="ir.ui.view">
<field name="name">Supplierinfo Duplicate</field>
<field name="model">product.supplierinfo.duplicate.wizard</field>
<field name="arch" type="xml">
<form>
<div>
Set new start date and variation percent to duplicate.
This process set start date previous day as end date of
origin record.
<br/>
<br/>
</div>
<group>
<group>
<field name="date_start"/>
<field name="date_end"/>
<field name="variation_percent"/>
</group>
</group>
<footer>
<button string="Apply" name="action_apply"
type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>

<act_window id="supplierinfo_duplicate_wizard_action"
name="Duplicate Supplier Info"
src_model="product.supplierinfo"
res_model="product.supplierinfo.duplicate.wizard"
view_type="form" view_mode="form"
key2="client_action_multi" target="new"
/>

</odoo>

0 comments on commit 7f4d0ed

Please sign in to comment.