sale order method when is maquila and pending delivered quantity
This commit is contained in:
parent
af37939a47
commit
9599353d59
26
maquila.py
26
maquila.py
|
@ -7,6 +7,7 @@ from trytond.modules.company.model import (
|
|||
CompanyMultiValueMixin, CompanyValueMixin)
|
||||
from trytond.i18n import gettext
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.model.modelstorage import AccessError
|
||||
|
||||
|
||||
def default_func(field_name):
|
||||
|
@ -390,7 +391,8 @@ class ContractCrop(ModelSQL, ModelView):
|
|||
currency_digits = fields.Function(fields.Integer('Currency Digits'),
|
||||
'on_change_with_currency_digits')
|
||||
product_years = fields.Many2Many(
|
||||
'agronomics.maquila.product_year-agronomics.maquila.contract.crop', 'contract_crop', 'product_year', "Product Years")
|
||||
'agronomics.maquila.product_year-agronomics.maquila.contract.crop',
|
||||
'contract_crop', 'product_year', "Product Years")
|
||||
maquilas = fields.Many2Many(
|
||||
'agronomics.maquila-agronomics.maquila.contract.crop',
|
||||
'contract_crop', 'maquila', "Maquila", readonly=True)
|
||||
|
@ -435,6 +437,10 @@ class ProductYear(ModelSQL, ModelView):
|
|||
delivered_quantity = fields.Function(fields.Float("Delivered Quantity",
|
||||
digits=(16, Eval('unit_digits', 2)),
|
||||
depends=['unit_digits']), 'get_delivered_quantity')
|
||||
pending_delivered_quantity = fields.Function(fields.Float(
|
||||
"Pending Delivered Quantity",
|
||||
digits=(16, Eval('unit_digits', 2)),
|
||||
depends=['unit_digits']), 'get_delivered_quantity')
|
||||
unit = fields.Many2One('product.uom', "Unit", required=True, readonly=True,
|
||||
ondelete='RESTRICT', domain=[
|
||||
If(Bool(Eval('product_uom_category')),
|
||||
|
@ -513,12 +519,15 @@ class ProductYear(ModelSQL, ModelView):
|
|||
return res
|
||||
|
||||
@classmethod
|
||||
def get_delivered_quantity(cls, product_years, name):
|
||||
def get_delivered_quantity(cls, product_years, names):
|
||||
pool = Pool()
|
||||
SaleLine = pool.get('sale.line')
|
||||
Uom = pool.get('product.uom')
|
||||
|
||||
res = dict((x.id, 0) for x in product_years)
|
||||
res = {n: {r.id: 0 for r in product_years} for n in names}
|
||||
|
||||
# get qty delivered from sales (moves)
|
||||
product_years_delivered = {}
|
||||
for product_year in product_years:
|
||||
lines = SaleLine.search([
|
||||
('maquila', '=', product_year),
|
||||
|
@ -532,7 +541,16 @@ class ProductYear(ModelSQL, ModelView):
|
|||
if not move.state == 'done':
|
||||
continue
|
||||
_sum += Uom.compute_qty(move.uom, move.quantity, product_year.unit, False)
|
||||
res[product_year.id] = _sum
|
||||
product_years_delivered[product_year.id] = _sum
|
||||
|
||||
for name in names:
|
||||
for product_year in product_years:
|
||||
delivered_quantity = product_years_delivered.get(product_year.id, 0)
|
||||
if name == 'delivered_quantity':
|
||||
res[name][product_year.id] = delivered_quantity
|
||||
elif name == 'pending_delivered_quantity':
|
||||
# TODO total qty from?
|
||||
res[name][product_year.id] = product_year.quantity - delivered_quantity
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
|
|
3
sale.py
3
sale.py
|
@ -64,7 +64,8 @@ class Sale(metaclass=PoolMeta):
|
|||
|
||||
@fields.depends('is_maquila')
|
||||
def on_change_is_maquila(self):
|
||||
self.invoice_method = 'order' if self.is_maquila else self.default_invoice_method()
|
||||
self.invoice_method = ('manual' if self.is_maquila
|
||||
else self.default_invoice_method())
|
||||
|
||||
@fields.depends('is_maquila')
|
||||
def on_change_party(self):
|
||||
|
|
|
@ -10,10 +10,12 @@
|
|||
<field name="product"/>
|
||||
<label name="quantity"/>
|
||||
<field name="quantity"/>
|
||||
<label name="delivered_quantity"/>
|
||||
<field name="delivered_quantity"/>
|
||||
<label name="unit"/>
|
||||
<field name="unit"/>
|
||||
<label name="delivered_quantity"/>
|
||||
<field name="delivered_quantity"/>
|
||||
<label name="pending_delivered_quantity"/>
|
||||
<field name="pending_delivered_quantity"/>
|
||||
<newline/>
|
||||
<field name="contract_crops" colspan="6"/>
|
||||
<field name="contracts" colspan="6"/>
|
||||
|
|
Loading…
Reference in New Issue