Skip to content

Commit

Permalink
Merge 7f22dd1 into fe9ac6d
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane committed Jun 22, 2015
2 parents fe9ac6d + 7f22dd1 commit 478b956
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
42 changes: 42 additions & 0 deletions sale_last_price_info/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

Product Last Price Info - Sale
==================================

This module adds the last sale info of the product.


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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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
`here <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_last_price_info%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.


Credits
=======

Contributors
------------
* Alfredo de la Fuente <alfredodelafuente@avanzosc.es>
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Ana Juaristi <anajuaristi@avanzosc.es>

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 http://odoo-community.org.
6 changes: 6 additions & 0 deletions sale_last_price_info/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################

from . import models
42 changes: 42 additions & 0 deletions sale_last_price_info/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# 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 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": "Product Last Price Info - Sale",
"version": "1.0",
"category": "Hidden/Dependency",
"license": "AGPL-3",
"author": "OdooMRP team, "
"AvanzOSC, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
"Odoo Community Association (OCA)",
"website": "http://www.odoomrp.com",
"contributors": [
"Alfredo de la Fuente <alfredodelafuente@avanzosc.es>",
"Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>",
"Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>",
"Ana Juaristi <anajuaristi@avanzosc.es>",
],
"depends": [
"sale",
],
"data": [
"views/product_view.xml",
],
"installable": True,
}
6 changes: 6 additions & 0 deletions sale_last_price_info/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################

from . import product
31 changes: 31 additions & 0 deletions sale_last_price_info/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################

from openerp import api, fields, models


class ProductProduct(models.Model):
_inherit = 'product.product'

@api.one
def _get_last_sale(self):
"""
Get last sale price, last sale date and last customer
"""
lines = self.env['sale.order.line'].search(
[('product_id', '=', self.id),
('state', 'in', ['confirmed', 'done'])]).sorted(
key=lambda l: l.order_id.date_order, reverse=True)
self.last_sale_date = lines[:1].order_id.date_order
self.last_sale_price = lines[:1].price_unit
self.last_customer = lines[:1].order_id.partner_id

last_sale_price = fields.Float(
string='Last Sale Price', compute='_get_last_sale')
last_sale_date = fields.Date(
string='Last Sale Date', compute='_get_last_sale')
last_customer = fields.Many2one(
comodel_name='res.partner', string='Last Customer',
compute='_get_last_sale')
31 changes: 31 additions & 0 deletions sale_last_price_info/views/product_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="product.product_last_info_page_form_view">
<field name="name">product.last.info.page.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<notebook position="inside">
<page string="Last Price Info"/>
</notebook>
</field>
</record>

<record model="ir.ui.view" id="product_last_sale_info_form_view">
<field name="name">product.last.sale.info.form</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_last_info_page_form_view" />
<field name="arch" type="xml">
<page string="Last Price Info" position="inside">
<group string="Sale" name="last_sale_info">
<field name="last_customer" />
<field name="last_sale_date" />
<field name="last_sale_price" />
</group>
</page>
</field>
</record>

</data>
</openerp>

0 comments on commit 478b956

Please sign in to comment.