Browse Source

[9.0] [ADD] partner_stock_risk (#300)

* [9.0][ADD] partner_stock_risk: New module

* [9.0][WIP] partner_stock_risk: New module

* [9.0][WIP] partner_stock_risk: Improve code

* [9.0][FIX] partner_stock_risk: Fix test

* [9.0][IMP] partner_stock_risk: Translate
pull/433/head
Carlos Dauden 8 years ago
committed by Rafael Blasco
parent
commit
7a7b2ba9c6
  1. 62
      partner_stock_risk/README.rst
  2. 3
      partner_stock_risk/__init__.py
  3. 15
      partner_stock_risk/__openerp__.py
  4. 45
      partner_stock_risk/i18n/es.po
  5. 3
      partner_stock_risk/models/__init__.py
  6. 68
      partner_stock_risk/models/stock.py
  7. 3
      partner_stock_risk/tests/__init__.py
  8. 38
      partner_stock_risk/tests/test_partner_stock_risk.py

62
partner_stock_risk/README.rst

@ -0,0 +1,62 @@
.. 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
==================
Partner Stock Risk
==================
Extends Partner Financial Risk to manage stock moves.
If any limit is exceed the partner gets forbidden to transfer stock move.
Usage
=====
To use this module, you need to:
#. Go to *Customers > Financial Risk*
#. Set limits and choose options to compute in credit limit
#. Go to *Inventory > All Operations*
#. Try transfer a risk exceed partner picking
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/134/9.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner-contact/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
=======
Contributors
------------
* Carlos Dauden <carlos.dauden@tecnativa.com>
* Pedro M. Baeza <pedro.baeza@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.

3
partner_stock_risk/__init__.py

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

15
partner_stock_risk/__openerp__.py

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Partner Stock Risk',
'summary': 'Manage partner risk in stock moves',
'version': '9.0.1.0.0',
'category': 'Sales Management',
'license': 'AGPL-3',
'author': 'Tecnativa, Odoo Community Association (OCA)',
'website': 'https://www.tecnativa.com',
'depends': ['stock', 'partner_financial_risk'],
'installable': True,
}

45
partner_stock_risk/i18n/es.po

@ -0,0 +1,45 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * partner_sale_risk
#
# Translators:
# Carlos Dauden <carlos.dauden@tecnativa.com>, 2017
msgid ""
msgstr ""
"Project-Id-Version: partner-contact (9.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-29 15:53+0200\n"
"PO-Revision-Date: 2017-05-29 15:54+0200\n"
"Last-Translator: Carlos Dauden <carlos.dauden@tecnativa.com>\n"
"Language-Team: Spanish (http://www.transifex.com/oca/OCA-partner-contact-9-0/"
"language/es/)\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"
#. module: partner_stock_risk
#: code:addons/partner_stock_risk/models/stock.py:31
#, python-format
msgid "Financial risk exceeded \n"
msgstr "Riesgo financiero excedido.\n"
#. module: partner_stock_risk
#: code:addons/partner_stock_risk/models/stock.py:20
#, python-format
msgid ""
"Financial risk exceeded in partner:\n"
"%s"
msgstr "Riesgo financiero excedido en empresa: %s"
#. module: partner_stock_risk
#: model:ir.model,name:partner_stock_risk.model_stock_move
msgid "Stock Move"
msgstr "Movimiento de existencias"
#. module: partner_stock_risk
#: model:ir.model,name:partner_stock_risk.model_stock_picking
msgid "Transfer"
msgstr "Transferir"

3
partner_stock_risk/models/__init__.py

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

68
partner_stock_risk/models/stock.py

@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import _, api, exceptions, models
class StockMove(models.Model):
_inherit = 'stock.move'
@api.multi
def action_done(self):
if not self.env.context.get('bypass_risk'):
moves = self.filtered(lambda x: (
x.location_dest_id.usage == 'customer' and
x.partner_id.risk_exception
))
if moves:
raise exceptions.UserError(
_("Financial risk exceeded in partner:\n%s") %
moves.mapped('partner_id.name'))
return super(StockMove, self).action_done()
class StockPicking(models.Model):
_inherit = 'stock.picking'
@api.multi
def show_risk_wizard(self, continue_method):
return self.env['partner.risk.exceeded.wiz'].create({
'exception_msg': _("Financial risk exceeded \n"),
'partner_id': self.partner_id.id,
'origin_reference': '%s,%s' % (self._model, self.id),
'continue_method': continue_method,
}).action_show()
@api.multi
def action_confirm(self):
if not self.env.context.get('bypass_risk'):
if (self.location_dest_id.usage == 'customer' and
self.partner_id.risk_exception):
return self.show_risk_wizard('action_confirm')
return super(StockPicking, self).action_confirm()
@api.multi
def action_assign(self):
if not self.env.context.get('bypass_risk') and \
self.filtered('partner_id.risk_exception'):
params = self.env.context.get('params', {})
if 'purchase.order' not in params and 'sale.order' not in params:
return self.show_risk_wizard('action_assign')
return super(StockPicking, self).action_assign()
@api.multi
def force_assign(self):
if not self.env.context.get('bypass_risk'):
if (self.location_dest_id.usage == 'customer' and
self.partner_id.risk_exception):
return self.show_risk_wizard('force_assign')
return super(StockPicking, self).force_assign()
@api.multi
def do_new_transfer(self):
if not self.env.context.get('bypass_risk'):
if (self.location_dest_id.usage == 'customer' and
self.partner_id.risk_exception):
return self.show_risk_wizard('do_new_transfer')
return super(StockPicking, self).do_new_transfer()

3
partner_stock_risk/tests/__init__.py

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

38
partner_stock_risk/tests/test_partner_stock_risk.py

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# © 2016 Carlos Dauden <carlos.dauden@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.tests.common import TransactionCase
class TestPartnerStocklRisk(TransactionCase):
def setUp(self):
super(TestPartnerStocklRisk, self).setUp()
self.partner = self.env['res.partner'].create({
'name': 'Partner test',
'customer': True,
})
self.product = self.env.ref('product.product_product_36')
self.quant = self.env['stock.quant'].create({
'qty': 100,
'location_id': self.env.ref('stock.stock_location_stock').id,
'product_id': self.product.id,
})
self.picking = self.env['stock.picking'].create({
'picking_type_id': self.env.ref('stock.picking_type_out').id,
'location_id': self.env.ref('stock.stock_location_stock').id,
'location_dest_id':
self.env.ref('stock.stock_location_customers').id,
})
self.move = self.env['stock.move'].create({
'name': '/',
'picking_id': self.picking.id,
'product_uom': self.product.uom_id.id,
'location_id': self.env.ref('stock.stock_location_stock').id,
'location_dest_id':
self.env.ref('stock.stock_location_customers').id,
'product_id': self.product.id,
})
def test_stock_move(self):
self.move.action_done()
Loading…
Cancel
Save