ad field stock quantity in line purchase

This commit is contained in:
wilson gomez 2021-11-22 08:37:05 -05:00
parent c827d7bee7
commit 8dea4c43e7
4 changed files with 47 additions and 1 deletions

View file

@ -9,4 +9,5 @@ def register():
Pool.register(
purchase.Configuration,
purchase.Purchase,
purchase.Line,
module='purchase_co', type_='model')

View file

@ -1,10 +1,11 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from datetime import date, timedelta
from trytond.pyson import Eval
from trytond.pool import PoolMeta, Pool
from trytond.model import fields
from trytond.exceptions import UserError
from trytond.transaction import Transaction
class Configuration(metaclass=PoolMeta):
@ -57,3 +58,33 @@ class Purchase(metaclass=PoolMeta):
], fields_names=['reference'])
if len(duplicates) >= 2:
raise UserError('Al parecer esta compra esta duplicada!')
class Line(metaclass=PoolMeta):
__name__ = 'purchase.line'
stock_quantity = fields.Function(fields.Float('Stock Quantity',
digits=(16, Eval('default_uom_digits', 2))),
'on_change_with_stock_quantity')
@fields.depends('product')
def on_change_with_stock_quantity(self, name=None):
if self.product:
context = {'stock_date_end': self.purchase.purchase_date}
Location = Pool().get('stock.location')
locations = Location.search([
('type', '=', 'warehouse')
])
location_ids = [l.storage_location.id for l in locations if l.storage_location]
product_ids = [self.product.id]
quantity = 0
with Transaction().set_context(context):
Product = Pool().get('product.product')
pbl = Product.products_by_location(
location_ids,
grouping=('product', ),
grouping_filter=(product_ids,))
for v in pbl.values():
quantity += v
quantity = quantity
return quantity

View file

@ -9,5 +9,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="inherit" ref="purchase.purchase_configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
<record model="ir.ui.view" id="purchase_line_view_form">
<field name="model">purchase.line</field>
<field name="inherit" ref="purchase.purchase_line_view_form"/>
<field name="name">purchase_line_form</field>
</record>
</data>
</tryton>

View file

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/notebook/page[@id='general']/group[@id='delivery_date']" position="after">
<label name="stock_quantity"/>
<field name="stock_quantity"/>
</xpath>
</data>