first commit
This commit is contained in:
2
modules/stock_shipment_cost_weight/__init__.py
Normal file
2
modules/stock_shipment_cost_weight/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
14
modules/stock_shipment_cost_weight/carrier.py
Normal file
14
modules/stock_shipment_cost_weight/carrier.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# 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 trytond.pool import PoolMeta
|
||||
|
||||
|
||||
class Carrier(metaclass=PoolMeta):
|
||||
__name__ = 'carrier'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls.shipment_cost_allocation_method.selection.append(
|
||||
('weight', "By Weight"))
|
||||
7
modules/stock_shipment_cost_weight/locale/bg.po
Normal file
7
modules/stock_shipment_cost_weight/locale/bg.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/ca.po
Normal file
7
modules/stock_shipment_cost_weight/locale/ca.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Per pes"
|
||||
7
modules/stock_shipment_cost_weight/locale/cs.po
Normal file
7
modules/stock_shipment_cost_weight/locale/cs.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/de.po
Normal file
7
modules/stock_shipment_cost_weight/locale/de.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Nach Gewicht"
|
||||
7
modules/stock_shipment_cost_weight/locale/es.po
Normal file
7
modules/stock_shipment_cost_weight/locale/es.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Por peso"
|
||||
7
modules/stock_shipment_cost_weight/locale/es_419.po
Normal file
7
modules/stock_shipment_cost_weight/locale/es_419.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/et.po
Normal file
7
modules/stock_shipment_cost_weight/locale/et.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/fa.po
Normal file
7
modules/stock_shipment_cost_weight/locale/fa.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/fi.po
Normal file
7
modules/stock_shipment_cost_weight/locale/fi.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/fr.po
Normal file
7
modules/stock_shipment_cost_weight/locale/fr.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Par poids"
|
||||
7
modules/stock_shipment_cost_weight/locale/hu.po
Normal file
7
modules/stock_shipment_cost_weight/locale/hu.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/id.po
Normal file
7
modules/stock_shipment_cost_weight/locale/id.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/it.po
Normal file
7
modules/stock_shipment_cost_weight/locale/it.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Per peso"
|
||||
7
modules/stock_shipment_cost_weight/locale/lo.po
Normal file
7
modules/stock_shipment_cost_weight/locale/lo.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/lt.po
Normal file
7
modules/stock_shipment_cost_weight/locale/lt.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/nl.po
Normal file
7
modules/stock_shipment_cost_weight/locale/nl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "Op gewicht"
|
||||
7
modules/stock_shipment_cost_weight/locale/pl.po
Normal file
7
modules/stock_shipment_cost_weight/locale/pl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/pt.po
Normal file
7
modules/stock_shipment_cost_weight/locale/pt.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
8
modules/stock_shipment_cost_weight/locale/ro.po
Normal file
8
modules/stock_shipment_cost_weight/locale/ro.po
Normal file
@@ -0,0 +1,8 @@
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr "După Greutate"
|
||||
7
modules/stock_shipment_cost_weight/locale/ru.po
Normal file
7
modules/stock_shipment_cost_weight/locale/ru.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/sl.po
Normal file
7
modules/stock_shipment_cost_weight/locale/sl.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/tr.po
Normal file
7
modules/stock_shipment_cost_weight/locale/tr.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/uk.po
Normal file
7
modules/stock_shipment_cost_weight/locale/uk.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
7
modules/stock_shipment_cost_weight/locale/zh_CN.po
Normal file
7
modules/stock_shipment_cost_weight/locale/zh_CN.po
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "selection:carrier,shipment_cost_allocation_method:"
|
||||
msgid "By Weight"
|
||||
msgstr ""
|
||||
37
modules/stock_shipment_cost_weight/stock.py
Normal file
37
modules/stock_shipment_cost_weight/stock.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# 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 decimal import Decimal
|
||||
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
|
||||
|
||||
class ShipmentCostMixinWeight:
|
||||
__slots__ = ()
|
||||
|
||||
def _get_allocation_shipment_cost_factors_by_weight(self):
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
if getattr(Move, 'internal_weight', None):
|
||||
sum_weight = Decimal(0)
|
||||
weights = {}
|
||||
for move in self.shipment_cost_moves:
|
||||
weight = Decimal(str(move.internal_weight or 0))
|
||||
weights[move.id] = weight
|
||||
sum_weight += weight
|
||||
|
||||
if sum_weight:
|
||||
factors = {}
|
||||
for move in self.shipment_cost_moves:
|
||||
factors[move.id] = weights[move.id] / sum_weight
|
||||
return factors
|
||||
return self._get_allocation_shipment_cost_factors_by_cost()
|
||||
|
||||
|
||||
class ShipmentOut(ShipmentCostMixinWeight, metaclass=PoolMeta):
|
||||
__name__ = 'stock.shipment.out'
|
||||
|
||||
|
||||
class ShipmentOutReturn(
|
||||
ShipmentCostMixinWeight, metaclass=PoolMeta):
|
||||
__name__ = 'stock.shipment.out.return'
|
||||
2
modules/stock_shipment_cost_weight/tests/__init__.py
Normal file
2
modules/stock_shipment_cost_weight/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,122 @@
|
||||
===================================
|
||||
Stock Shipment Cost Weight Scenario
|
||||
===================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
>>> from unittest.mock import patch
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.modules.currency.tests.tools import get_currency
|
||||
>>> from trytond.modules.stock_shipment_cost.stock import ShipmentCostMixin
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Patch _get_shipment_cost::
|
||||
|
||||
>>> mock = patch.object(
|
||||
... ShipmentCostMixin, '_get_shipment_cost',
|
||||
... return_value=Decimal('8')).start()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('stock_shipment_cost_weight', create_company)
|
||||
|
||||
>>> Carrier = Model.get('carrier')
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> Shipment = Model.get('stock.shipment.out')
|
||||
|
||||
Get currency::
|
||||
|
||||
>>> currency = get_currency()
|
||||
|
||||
Create customer::
|
||||
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create products::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', "Unit")])
|
||||
>>> gram, = ProductUom.find([('name', '=', "Gram")])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product1"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.weight = 500
|
||||
>>> template.weight_uom = gram
|
||||
>>> template.save()
|
||||
>>> product1, = template.products
|
||||
>>> product1.cost_price = Decimal('10.0000')
|
||||
>>> product1.save()
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product2"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.weight = 250
|
||||
>>> template.weight_uom = gram
|
||||
>>> template.save()
|
||||
>>> product2, = template.products
|
||||
>>> product2.cost_price = Decimal('20.0000')
|
||||
>>> product2.save()
|
||||
|
||||
>>> carrier_template = ProductTemplate()
|
||||
>>> carrier_template.name = "Carrier Product"
|
||||
>>> carrier_template.default_uom = unit
|
||||
>>> carrier_template.type = 'service'
|
||||
>>> carrier_template.save()
|
||||
>>> carrier_product, = carrier_template.products
|
||||
|
||||
Create carrier::
|
||||
|
||||
>>> carrier = Carrier()
|
||||
>>> carrier.party = Party(name="Carrier")
|
||||
>>> carrier.party.save()
|
||||
>>> carrier.carrier_product = carrier_product
|
||||
>>> carrier.shipment_cost_allocation_method = 'weight'
|
||||
>>> carrier.save()
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
|
||||
>>> output_loc, = Location.find([('code', '=', 'OUT')])
|
||||
|
||||
Create a customer shipment::
|
||||
|
||||
>>> shipment = Shipment()
|
||||
>>> shipment.customer = customer
|
||||
>>> shipment.carrier = carrier
|
||||
>>> move = shipment.outgoing_moves.new()
|
||||
>>> move.product = product1
|
||||
>>> move.quantity = 1
|
||||
>>> move.from_location = output_loc
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.unit_price = Decimal('30')
|
||||
>>> move.currency = currency
|
||||
>>> move = shipment.outgoing_moves.new()
|
||||
>>> move.product = product2
|
||||
>>> move.quantity = 2
|
||||
>>> move.from_location = output_loc
|
||||
>>> move.to_location = customer_loc
|
||||
>>> move.unit_price = Decimal('40')
|
||||
>>> move.currency = currency
|
||||
>>> shipment.click('wait')
|
||||
>>> shipment.click('assign_force')
|
||||
>>> shipment.click('pick')
|
||||
>>> shipment.click('pack')
|
||||
>>> shipment.click('do')
|
||||
>>> shipment.state
|
||||
'done'
|
||||
|
||||
Check move costs::
|
||||
|
||||
>>> sorted([
|
||||
... (m.cost_price, m.shipment_out_cost_price)
|
||||
... for m in shipment.outgoing_moves])
|
||||
[(Decimal('10.0000'), Decimal('4.0000')), (Decimal('20.0000'), Decimal('2.0000'))]
|
||||
12
modules/stock_shipment_cost_weight/tests/test_module.py
Normal file
12
modules/stock_shipment_cost_weight/tests/test_module.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# 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 trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class StockShipmentCostWeightTestCase(ModuleTestCase):
|
||||
'Test Stock Shipment Cost Weight module'
|
||||
module = 'stock_shipment_cost_weight'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
@@ -0,0 +1,8 @@
|
||||
# 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 trytond.tests.test_tryton import load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
13
modules/stock_shipment_cost_weight/tryton.cfg
Normal file
13
modules/stock_shipment_cost_weight/tryton.cfg
Normal file
@@ -0,0 +1,13 @@
|
||||
[tryton]
|
||||
version=7.8.0
|
||||
depends:
|
||||
carrier
|
||||
ir
|
||||
stock_shipment_cost
|
||||
stock_shipment_measurements
|
||||
|
||||
[register]
|
||||
model:
|
||||
carrier.Carrier
|
||||
stock.ShipmentOut
|
||||
stock.ShipmentOutReturn
|
||||
Reference in New Issue
Block a user