Skip to content

Commit

Permalink
[DONOTMERGE] PR depends
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Dec 19, 2024
1 parent a34610d commit 5bf21b5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 46 deletions.
24 changes: 12 additions & 12 deletions shopinvader_api_cart_options/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Shopinvader API Cart Options
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:946cd22cb562f3d64d31537d9fdfb741356c31fcfa820646b6827b07492a263a
!! source digest: sha256:a79d0b44a91d73aa4ec75b5dc399fac8130e6bc08cf5228ce0a6da8b4c81eba0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -45,13 +45,13 @@ add your own options:
.. code:: python
class SaleLineOptions(BaseSaleLineOptions, extends=True):
note: str | None = None
engraving: str | None = None
special: bool = False
@classmethod
def from_sale_order_line(cls, odoo_rec):
rv = super().from_sale_order_line(odoo_rec)
rv.note = odoo_rec.note or None
rv.engraving = odoo_rec.carving or None
rv.special = odoo_rec.special
return rv
Expand All @@ -62,27 +62,27 @@ for you options in the cart line matching and in the cart line transfer:
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
note = fields.Char()
carving = fields.Char()
special = fields.Boolean()
def _match_cart_line(
self,
product_id,
note=None,
carving=None,
special=None,
**kwargs,
):
rv = super()._match_cart_line(
product_id,
note=note,
carving=carving,
special=special,
**kwargs,
)
return rv and self.note == note and self.special == special
return rv and self.carving == carving and self.special == special
def _prepare_cart_line_transfer_values(self):
vals = super()._prepare_cart_line_transfer_values()
vals["note"] = self.note
vals["carving"] = self.carving
vals["special"] = self.special
return vals
Expand All @@ -92,7 +92,9 @@ the cart line creation from the transaction API:

.. code:: python
class ShopinvaderApiCartRouterHelper(models.AbstractModel):
class ShopinvaderApiCartRouterHelper(
models.AbstractModel
): # pylint: disable=consider-merging-classes-inherited
_inherit = "shopinvader_api_cart.cart_router.helper"
@api.model
Expand All @@ -101,9 +103,7 @@ the cart line creation from the transaction API:
):
options = transactions[0].options
if options:
if options.note is not None:
values["note"] = options.note
values["carving"] = options.engraving
values["special"] = options.special
return values
Expand Down
22 changes: 11 additions & 11 deletions shopinvader_api_cart_options/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ options:

```python
class SaleLineOptions(BaseSaleLineOptions, extends=True):
note: str | None = None
engraving: str | None = None
special: bool = False

@classmethod
def from_sale_order_line(cls, odoo_rec):
rv = super().from_sale_order_line(odoo_rec)
rv.note = odoo_rec.note or None
rv.engraving = odoo_rec.carving or None
rv.special = odoo_rec.special
return rv
```
Expand All @@ -23,27 +23,27 @@ the cart line matching and in the cart line transfer:
```python
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
note = fields.Char()
carving = fields.Char()
special = fields.Boolean()

def _match_cart_line(
self,
product_id,
note=None,
carving=None,
special=None,
**kwargs,
):
rv = super()._match_cart_line(
product_id,
note=note,
carving=carving,
special=special,
**kwargs,
)
return rv and self.note == note and self.special == special
return rv and self.carving == carving and self.special == special

def _prepare_cart_line_transfer_values(self):
vals = super()._prepare_cart_line_transfer_values()
vals["note"] = self.note
vals["carving"] = self.carving
vals["special"] = self.special
return vals
```
Expand All @@ -52,7 +52,9 @@ And finally, you will need to extend the `ShopinvaderApiCartRouterHelper` to add
for your options in the cart line creation from the transaction API:

```python
class ShopinvaderApiCartRouterHelper(models.AbstractModel):
class ShopinvaderApiCartRouterHelper(
models.AbstractModel
): # pylint: disable=consider-merging-classes-inherited
_inherit = "shopinvader_api_cart.cart_router.helper"

@api.model
Expand All @@ -61,9 +63,7 @@ class ShopinvaderApiCartRouterHelper(models.AbstractModel):
):
options = transactions[0].options
if options:
if options.note is not None:
values["note"] = options.note

values["carving"] = options.engraving
values["special"] = options.special

return values
Expand Down
24 changes: 12 additions & 12 deletions shopinvader_api_cart_options/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ <h1 class="title">Shopinvader API Cart Options</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:946cd22cb562f3d64d31537d9fdfb741356c31fcfa820646b6827b07492a263a
!! source digest: sha256:a79d0b44a91d73aa4ec75b5dc399fac8130e6bc08cf5228ce0a6da8b4c81eba0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_api_cart_options"><img alt="shopinvader/odoo-shopinvader" src="https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github" /></a></p>
<p>This module allows to add options to the cart lines, grouping cart
Expand Down Expand Up @@ -396,13 +396,13 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
add your own options:</p>
<pre class="code python literal-block">
<span class="k">class</span> <span class="nc">SaleLineOptions</span><span class="p">(</span><span class="n">BaseSaleLineOptions</span><span class="p">,</span> <span class="n">extends</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span><span class="w">
</span> <span class="n">note</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="w">
</span> <span class="n">engraving</span><span class="p">:</span> <span class="nb">str</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="w">
</span> <span class="n">special</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="w">

</span> <span class="nd">&#64;classmethod</span><span class="w">
</span> <span class="k">def</span> <span class="nf">from_sale_order_line</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">odoo_rec</span><span class="p">):</span><span class="w">
</span> <span class="n">rv</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">from_sale_order_line</span><span class="p">(</span><span class="n">odoo_rec</span><span class="p">)</span><span class="w">
</span> <span class="n">rv</span><span class="o">.</span><span class="n">note</span> <span class="o">=</span> <span class="n">odoo_rec</span><span class="o">.</span><span class="n">note</span> <span class="ow">or</span> <span class="kc">None</span><span class="w">
</span> <span class="n">rv</span><span class="o">.</span><span class="n">engraving</span> <span class="o">=</span> <span class="n">odoo_rec</span><span class="o">.</span><span class="n">carving</span> <span class="ow">or</span> <span class="kc">None</span><span class="w">
</span> <span class="n">rv</span><span class="o">.</span><span class="n">special</span> <span class="o">=</span> <span class="n">odoo_rec</span><span class="o">.</span><span class="n">special</span><span class="w">
</span> <span class="k">return</span> <span class="n">rv</span>
</pre>
Expand All @@ -411,35 +411,37 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<pre class="code python literal-block">
<span class="k">class</span> <span class="nc">SaleOrderLine</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span><span class="w">
</span> <span class="n">_inherit</span> <span class="o">=</span> <span class="s2">&quot;sale.order.line&quot;</span><span class="w">
</span> <span class="n">note</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Char</span><span class="p">()</span><span class="w">
</span> <span class="n">carving</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Char</span><span class="p">()</span><span class="w">
</span> <span class="n">special</span> <span class="o">=</span> <span class="n">fields</span><span class="o">.</span><span class="n">Boolean</span><span class="p">()</span><span class="w">

</span> <span class="k">def</span> <span class="nf">_match_cart_line</span><span class="p">(</span><span class="w">
</span> <span class="bp">self</span><span class="p">,</span><span class="w">
</span> <span class="n">product_id</span><span class="p">,</span><span class="w">
</span> <span class="n">note</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="w">
</span> <span class="n">carving</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="w">
</span> <span class="n">special</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span><span class="w">
</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span><span class="w">
</span> <span class="p">):</span><span class="w">
</span> <span class="n">rv</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_match_cart_line</span><span class="p">(</span><span class="w">
</span> <span class="n">product_id</span><span class="p">,</span><span class="w">
</span> <span class="n">note</span><span class="o">=</span><span class="n">note</span><span class="p">,</span><span class="w">
</span> <span class="n">carving</span><span class="o">=</span><span class="n">carving</span><span class="p">,</span><span class="w">
</span> <span class="n">special</span><span class="o">=</span><span class="n">special</span><span class="p">,</span><span class="w">
</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span><span class="w">
</span> <span class="p">)</span><span class="w">
</span> <span class="k">return</span> <span class="n">rv</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">note</span> <span class="o">==</span> <span class="n">note</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">special</span> <span class="o">==</span> <span class="n">special</span><span class="w">
</span> <span class="k">return</span> <span class="n">rv</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">carving</span> <span class="o">==</span> <span class="n">carving</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">special</span> <span class="o">==</span> <span class="n">special</span><span class="w">

</span> <span class="k">def</span> <span class="nf">_prepare_cart_line_transfer_values</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span><span class="w">
</span> <span class="n">vals</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_prepare_cart_line_transfer_values</span><span class="p">()</span><span class="w">
</span> <span class="n">vals</span><span class="p">[</span><span class="s2">&quot;note&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">note</span><span class="w">
</span> <span class="n">vals</span><span class="p">[</span><span class="s2">&quot;carving&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">carving</span><span class="w">
</span> <span class="n">vals</span><span class="p">[</span><span class="s2">&quot;special&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">special</span><span class="w">
</span> <span class="k">return</span> <span class="n">vals</span>
</pre>
<p>And finally, you will need to extend the
<tt class="docutils literal">ShopinvaderApiCartRouterHelper</tt> to add support for your options in
the cart line creation from the transaction API:</p>
<pre class="code python literal-block">
<span class="k">class</span> <span class="nc">ShopinvaderApiCartRouterHelper</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">AbstractModel</span><span class="p">):</span><span class="w">
<span class="k">class</span> <span class="nc">ShopinvaderApiCartRouterHelper</span><span class="p">(</span><span class="w">
</span> <span class="n">models</span><span class="o">.</span><span class="n">AbstractModel</span><span class="w">
</span><span class="p">):</span> <span class="c1"># pylint: disable=consider-merging-classes-inherited</span><span class="w">
</span> <span class="n">_inherit</span> <span class="o">=</span> <span class="s2">&quot;shopinvader_api_cart.cart_router.helper&quot;</span><span class="w">

</span> <span class="nd">&#64;api</span><span class="o">.</span><span class="n">model</span><span class="w">
Expand All @@ -448,9 +450,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
</span> <span class="p">):</span><span class="w">
</span> <span class="n">options</span> <span class="o">=</span> <span class="n">transactions</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">options</span><span class="w">
</span> <span class="k">if</span> <span class="n">options</span><span class="p">:</span><span class="w">
</span> <span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">note</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span><span class="w">
</span> <span class="n">values</span><span class="p">[</span><span class="s2">&quot;note&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">note</span><span class="w">

</span> <span class="n">values</span><span class="p">[</span><span class="s2">&quot;carving&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">engraving</span><span class="w">
</span> <span class="n">values</span><span class="p">[</span><span class="s2">&quot;special&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">special</span><span class="w">

</span> <span class="k">return</span> <span class="n">values</span>
Expand Down
14 changes: 6 additions & 8 deletions shopinvader_api_cart_options/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@

class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
engraving = fields.Char()
carving = fields.Char()
special = fields.Boolean()

def _match_cart_line(
self,
product_id,
engraving=None,
carving=None,
special=None,
**kwargs,
):
rv = super()._match_cart_line(
product_id,
engraving=engraving,
carving=carving,
special=special,
**kwargs,
)
return rv and self.engraving == engraving and self.special == special
return rv and self.carving == carving and self.special == special

def _prepare_cart_line_transfer_values(self):
vals = super()._prepare_cart_line_transfer_values()
vals["engraving"] = self.engraving
vals["carving"] = self.carving
vals["special"] = self.special
return vals

Expand All @@ -47,9 +47,7 @@ def _apply_transactions_creating_new_cart_line_prepare_vals(
):
options = transactions[0].options
if options:
if options.engraving is not None:
values["engraving"] = options.engraving

values["carving"] = options.engraving
values["special"] = options.special

return values
2 changes: 1 addition & 1 deletion shopinvader_api_cart_options/tests/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class SaleLineOptions(BaseSaleLineOptions, extends=True):
@classmethod
def from_sale_order_line(cls, odoo_rec):
rv = super().from_sale_order_line(odoo_rec)
rv.engraving = odoo_rec.engraving or None
rv.engraving = odoo_rec.carving or None
rv.special = odoo_rec.special
return rv
5 changes: 3 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ unittest2 # For shopinvader test_controller, which inherits component
odoo-test-helper
httpx # For FastAPI tests

odoo-addon-shopinvader_api_customer @ git+https://github.com/shopinvader/odoo-shopinvader@refs/pull/1551/head#subdirectory=setup/shopinvader_api_customer
odoo-addon-shopinvader_api_settings @ git+https://github.com/shopinvader/odoo-shopinvader@refs/pull/1555/head#subdirectory=setup/shopinvader_api_settings
odoo-addon-shopinvader_sale_cart @ git+https://github.com/shopinvader/odoo-shopinvader@refs/pull/1575/head#subdirectory=setup/shopinvader_sale_cart
odoo-addon-shopinvader_api_cart @ git+https://github.com/shopinvader/odoo-shopinvader@refs/pull/1575/head#subdirectory=setup/shopinvader_api_cart
odoo-addon-extendable @ git+https://github.com/OCA/rest-framework@refs/pull/482/head#subdirectory=setup/extendable

0 comments on commit 5bf21b5

Please sign in to comment.