Extend Enough stock third modules + update current stock when have same product (lines or sales)
This commit is contained in:
parent
ff4288be80
commit
9055d45327
2
README
2
README
|
@ -1,7 +1,7 @@
|
|||
trytond-sale_product_stock
|
||||
==========================
|
||||
|
||||
The sale.product.stock module of the Tryton application platform.
|
||||
The sale product stock module of the Tryton application platform.
|
||||
|
||||
Installing
|
||||
----------
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.pool import Pool
|
||||
from .configuration import *
|
||||
from .sale import *
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
Configuration,
|
||||
Sale,
|
||||
module='sale_product_stock', type_='model')
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#This file is part sale_product_stock module for Tryton.
|
||||
#The COPYRIGHT file at the top level of this repository contains
|
||||
#the full copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
|
||||
__all__ = ['Configuration']
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
|
||||
class Configuration:
|
||||
__name__ = 'sale.configuration'
|
||||
enough_stock_qty = fields.Property(fields.Selection([
|
||||
('quantity', 'Quantity'),
|
||||
('forecast_quantity', 'Forecast Quantity'),
|
||||
], 'Quantity Stock',
|
||||
help='Manage Stock is Product Quantity or Product Forecast Quantity'))
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part esale module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="sale_configuration_view_form">
|
||||
<field name="model">sale.configuration</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit" ref="sale.sale_configuration_view_form"/>
|
||||
<field name="name">configuration_form</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
|
@ -1,6 +1,6 @@
|
|||
===========================
|
||||
Venta por estoc de producto
|
||||
===========================
|
||||
==============================
|
||||
Stock del producto en la venta
|
||||
==============================
|
||||
|
||||
Avisa que no hay suficiente cantidad de producto en el almacén para hacer la
|
||||
venta en caso de que la cantidad que se desee vender sea superior a la cantidad
|
||||
|
|
40
sale.py
40
sale.py
|
@ -25,16 +25,46 @@ class Sale:
|
|||
super(Sale, cls).quote(sales)
|
||||
cls.enough_stock(sales)
|
||||
|
||||
@classmethod
|
||||
def check_enough_stock(cls):
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def get_enough_stock_qty(cls):
|
||||
Config = Pool().get('sale.configuration')
|
||||
return Config(1).enough_stock_qty or 'quantity'
|
||||
|
||||
@classmethod
|
||||
def enough_stock(cls, sales):
|
||||
if not cls.check_enough_stock():
|
||||
return
|
||||
|
||||
Product = Pool().get('product.product')
|
||||
|
||||
# get all products
|
||||
products = []
|
||||
for sale in sales:
|
||||
locations = [sale.warehouse.id]
|
||||
for line in sale.lines:
|
||||
if not line.product or line.product.type not in PRODUCT_TYPES:
|
||||
continue
|
||||
with Transaction().set_context(locations=locations):
|
||||
quantity = Product.get_quantity([line.product], 'quantity')
|
||||
if not quantity or quantity[line.product.id] < line.quantity:
|
||||
cls.raise_user_warning('not_enough_stock_%s' % line.id,
|
||||
'not_enough_stock', line.product.name)
|
||||
if line.product not in products:
|
||||
products.append(line.product)
|
||||
|
||||
# get quantity
|
||||
with Transaction().set_context(locations=locations):
|
||||
quantities = Product.get_quantity(
|
||||
[line.product],
|
||||
cls.get_enough_stock_qty(),
|
||||
)
|
||||
|
||||
# check enough stock
|
||||
for sale in sales:
|
||||
for line in sale.lines:
|
||||
if line.product and line.product.id in quantities:
|
||||
qty = quantities[line.product.id]
|
||||
if qty < line.quantity:
|
||||
cls.raise_user_warning('not_enough_stock_%s' % line.id,
|
||||
'not_enough_stock', line.product.name)
|
||||
# update quantities
|
||||
quantities[line.product.id] = qty - line.quantity
|
||||
|
|
|
@ -13,8 +13,16 @@ class SaleProductStockTestCase(unittest.TestCase):
|
|||
def setUp(self):
|
||||
trytond.tests.test_tryton.install_module('sale_product_stock')
|
||||
|
||||
def test0005views(self):
|
||||
'''
|
||||
Test views.
|
||||
'''
|
||||
test_view('sale_product_stock')
|
||||
|
||||
def test0006depends(self):
|
||||
'Test depends'
|
||||
'''
|
||||
Test depends.
|
||||
'''
|
||||
test_depends()
|
||||
|
||||
|
||||
|
|
|
@ -4,3 +4,5 @@ depends:
|
|||
ir
|
||||
res
|
||||
sale
|
||||
xml:
|
||||
configuration.xml
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part sale_product_stock module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/field[@name="sale_shipment_method"]" position="after">
|
||||
<label name="enough_stock_qty"/>
|
||||
<field name="enough_stock_qty"/>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in New Issue