Set WholeSaleUnit to altUnit if Extra1 is not set. Fix webUserName.

This commit is contained in:
Marcus Lindvall 2019-09-05 15:26:18 +02:00
parent 0af38e286e
commit ee902ee733
3 changed files with 33 additions and 16 deletions

View file

@ -97,8 +97,8 @@ class Article(RawBaseModel):
'Edit': 'ArticleLongSpec',
'LagSaldoArtikel': 'UnitBalance',
'EnhetsKod': 'Unit',
'ArtListPris': 'UnitListPrice',
'Extra1': 'WholeSaleUnit'}
# 'Extra1': 'WholeSaleUnit',
'ArtListPris': 'UnitListPrice'}
__to_dict_only__ = (
'ArtNr',
'ArtBeskr',
@ -114,7 +114,8 @@ class Article(RawBaseModel):
'ArtListPris',
'PictureFileName',
'UnitListPrice',
'Extra1',
# 'Extra1',
'WholeSaleUnit',
'ListPrice',
'Balance')
@ -131,19 +132,32 @@ class Article(RawBaseModel):
ArticleUnit = relationship(ArticleUnit)
def _get_standard_alt_unit(self):
for unit in self.ArticleUnit:
if unit.AltEnhetOrderStd == "1":
return unit
def get_unit_conv(self):
if self.ArtFsgForp:
return self.ArtFsgForp
for unit in self.ArticleUnit:
if unit.AltEnhetOrderStd == "1":
if unit.AltEnhetOmrFaktor:
return unit.AltEnhetOmrFaktor
else:
return unit.ArticleAlternativeUnit.AltEnhetOmrFaktor
unit = self._get_standard_alt_unit()
if unit and unit.AltEnhetOmrFaktor:
return unit.AltEnhetOmrFaktor
else:
return unit.ArticleAlternativeUnit.AltEnhetOmrFaktor
return 1
@hybrid_property
def WholeSaleUnit(self):
if self.Extra1:
return self.Extra1
unit = self._get_standard_alt_unit()
if unit and not self.ArtFsgForp:
return unit.ArticleAlternativeUnit.AltEnhetBeskr
@hybrid_property
def ListPrice(self):
try:
@ -330,12 +344,13 @@ class Order(RawBaseModel):
self['OrderNr'], invoicing_possible = OrderHead(self['FtgNr'], webusername).callproc()
return self, invoicing_possible
def save(self, invoiced=False):
def save(self, invoiced=False, webusername=None):
payment_method = 'invoice'
if not invoiced:
payment_method = 'card'
PlaceOrder(
self['FtgNr'], self['OrderNr'], payment_method, data=self.to_dict()).callproc()
self['FtgNr'], self['OrderNr'], webusername,
payment_method, data=self.to_dict()).callproc()
return self