Added 'WholeSaleAmount' to Article, and refactored article internal functions
This commit is contained in:
parent
cf7ed09049
commit
a23e88ff2f
1 changed files with 25 additions and 13 deletions
|
|
@ -116,6 +116,7 @@ class Article(RawBaseModel):
|
||||||
'UnitListPrice',
|
'UnitListPrice',
|
||||||
# 'Extra1',
|
# 'Extra1',
|
||||||
'WholeSaleUnit',
|
'WholeSaleUnit',
|
||||||
|
'WholeSaleAmount',
|
||||||
'ListPrice',
|
'ListPrice',
|
||||||
'Balance')
|
'Balance')
|
||||||
|
|
||||||
|
|
@ -130,33 +131,44 @@ class Article(RawBaseModel):
|
||||||
ArticleClass = relationship(ArticleClass, lazy='joined')
|
ArticleClass = relationship(ArticleClass, lazy='joined')
|
||||||
ArticleBalance = relationship(ArticleBalance)
|
ArticleBalance = relationship(ArticleBalance)
|
||||||
|
|
||||||
ArticleUnit = relationship(ArticleUnit)
|
ArticleUnit = relationship(ArticleUnit, uselist=True)
|
||||||
|
|
||||||
|
def _get_alt_unit(self):
|
||||||
|
# Find matching alternative unit for amount per piece, or return default for the article.
|
||||||
|
spec_conv = self.ArtFsgForp if self.ArtFsgForp else None
|
||||||
|
|
||||||
def _get_standard_alt_unit(self):
|
|
||||||
for unit in self.ArticleUnit:
|
for unit in self.ArticleUnit:
|
||||||
if unit.AltEnhetOrderStd == "1":
|
if unit.AltEnhetOrderStd == "1" and not spec_conv:
|
||||||
|
return unit
|
||||||
|
elif (spec_conv and (unit.AltEnhetOmrFaktor == spec_conv or
|
||||||
|
unit.ArticleAlternativeUnit.AltEnhetOmrFaktor == spec_conv)):
|
||||||
return unit
|
return unit
|
||||||
|
|
||||||
def get_unit_conv(self):
|
def get_unit_conv(self):
|
||||||
|
# Return conversion factor for the article's alternative unit
|
||||||
if self.ArtFsgForp:
|
if self.ArtFsgForp:
|
||||||
return self.ArtFsgForp
|
return self.ArtFsgForp
|
||||||
|
|
||||||
unit = self._get_standard_alt_unit()
|
unit = self._get_alt_unit()
|
||||||
if unit and unit.AltEnhetOmrFaktor:
|
if unit:
|
||||||
return unit.AltEnhetOmrFaktor
|
return (unit.AltEnhetOmrFaktor if unit.AltEnhetOmrFaktor
|
||||||
elif unit:
|
else unit.ArticleAlternativeUnit.AltEnhetOmrFaktor)
|
||||||
return unit.ArticleAlternativeUnit.AltEnhetOmrFaktor
|
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@hybrid_property
|
@hybrid_property
|
||||||
def WholeSaleUnit(self):
|
def WholeSaleUnit(self):
|
||||||
if self.Extra1:
|
# Description of alternative unit, or Extra1 if no alternative unit is in use.
|
||||||
|
unit = self._get_alt_unit()
|
||||||
|
if unit:
|
||||||
|
return unit.ArticleAlternativeUnit.AltEnhetBeskr
|
||||||
|
else:
|
||||||
return self.Extra1
|
return self.Extra1
|
||||||
|
|
||||||
unit = self._get_standard_alt_unit()
|
@hybrid_property
|
||||||
if unit and not self.ArtFsgForp:
|
def WholeSaleAmount(self):
|
||||||
return unit.ArticleAlternativeUnit.AltEnhetBeskr
|
# Amount of units in the alternative unit of the article, or 1 if none exist.
|
||||||
|
return self.get_unit_conv()
|
||||||
|
|
||||||
@hybrid_property
|
@hybrid_property
|
||||||
def ListPrice(self):
|
def ListPrice(self):
|
||||||
|
|
@ -176,7 +188,7 @@ class Article(RawBaseModel):
|
||||||
def _base_filters(self, obj):
|
def _base_filters(self, obj):
|
||||||
return RawBaseModel._base_filters(
|
return RawBaseModel._base_filters(
|
||||||
obj,
|
obj,
|
||||||
and_(obj.LagTyp == 0)
|
and_(obj.ItemStatusCode == 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue